简体   繁体   中英

batch file to run recursively

I would like to run command line utility recursively for all folders in windows. I have tried with the following, but not succesfully.

FOR /R "C:\AMDB\30-Apr-2013\Input\" %%G in (.) DO (

shp2sdo.exe %%~ni %%~ni -g geometry -d -x (-180,180) -y (-90,90) -s 8307 -t 0.5 -v

Pushd %%G
Echo now in %%G
Popd )
Echo "back home"

try this:

@echo off &setlocal
FOR /R /D "C:\AMDB\30-Apr-2013\Input" %%G in (*) DO (
    Pushd "%%G"
    shp2sdo.exe "%%~ni" "%%~ni" -g geometry -d -x (-180,180) -y (-90,90) -s 8307 -t 0.5 -v
    Echo now in %%G
    Popd 
)
Echo "back home"

We have no idea of what you mean by "successfully." We can conclude it's not doing what you expect, otherwise you'd not be asking the question.

Now - is the problem that it's not running your utility in "all folders"?

  • You are only asking it to run in "C:\\AMDB\\30-Apr-2013\\Input\\" and directories in that subtree.

Are you showing us just the part you believe is at fault?

  • Perhaps shp2sdo.exe %%~nG rather than shp2sdo.exe %%~ni would work better for you

Or is it not giving you what you expect when you ECHO now in %%G ?

  • Perhaps if you told us what you expect and what you're getting it may be easier to help.

The reason your code does not execute is because the ) characters in your SHP2SDO.EXE arguments are closing your FOR DO loop prematurely. Those parentheses need to be escaped:

FOR /R "C:\AMDB\30-Apr-2013\Input\" %%G in (.) DO (

  shp2sdo.exe %%~ni %%~ni -g geometry -d -x (-180,180^) -y (-90,90^) -s 8307 -t 0.5 -v

  Pushd %%G
  Echo now in %%G
  Popd
)
Echo "back home"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM