Batch script to build ruby gems -


i have following directory structure.

build   -build.bat package   -gems     -abc.gem     -xyz.gem   -install.sh plugins   -abc     -abc.gemspec   -xyz     -xyz.gemspec 

i trying write batch file build.bat in build folder. tasks should perform :

  1. delete previous files in package/gems folder
  2. inside each subdirectory of plugins folder, execute

    gem build *.gemspec

    this command create gem file in same directory.

  3. move gem file created package/gems folder

i have been going through batch programming syntax, , not sure whether can achieved batch script or not. how can write batch script these tasks?

[edit]

after basic research able accomplish lot of tasks.

@echo on  cd.. set cur_dir=%cd% set gems_dir=%cur_dir%\package\gems set plugins_dir=%cur_dir%\plugins  del /f/s/q/a %gems_dir%\  cd %plugins_dir%  /d %%d in (*) (     pushd %%~fd      gem build *.gemspec     move *.gem %gems_dir%     popd ) 

however, move command copies both .gem , .gemspec files. how restrict move .gem files? also, lines added after last parenthesis not execute. other improvements appreciated. thank you.

[edit2]

any lines added after foor loop not being executed. after adding call infront of gem command, works fine.

replace the

move *.gem %gems_dir% 

with

for /f "delims=" %%a in ('dir /b /a-d *.gem* ^|findstr /e /l /i ".gem" 2^>nul') move "%%a" "%gems_dir%" 

noting:

the %%a in for statement can alphabetic (other d used outer loop) , is case-sensitive, whereas batch otherwise case-insensitive far instructions , variables concerned.

this generates /b (basic) dir listing (ie. names only) /a-d without directorynames, of files matching *.gem*. naturally select *.gem , *.gemspec files (which being picked move *.gem because have short-name of something with~n.gem (see dir /x listing).

having generated listing (in memory), pipe list findstr find lines (ie. filenames) /e end /l literal /i case-insensitive ".gem". ^ escapes redirector characters tell cmd redirector part of single-quoted command-to-executed not of for. 2>nul redirects unwanted "not found" output findstr nowhere should appear (redirecting 2=stderr).

the forassigns entirety of line (=filename may contain spaces) %%a since "delims=" means "no delimiters"

hence, %%a should contain names of file(s) end .gem.

and quoting policy - escapes standard operation of separators space , removes special meaning.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -