简体   繁体   中英

edit a raster using batch file in command line

I am trying to write a batch file for windows command line to convert values of 0 to 1. I can change the numbers with ease but am struggling with the batch file process. I want the batch file to search through 3 degrees of folders to find images to process. So far I have... UPDATE: The problem appears to have been solved. But for reference the batch file didn't seem to be working, no error messages, just no output.

for %%y in (D:\Data\imageA\20*) do (
    cd %%y
    for %%m in (\%%y\*) do (
        cd %%m
        for %%d in (\%%m\*) do (
            cd %%d
            for %%f in (imageA_*_raster) do replacetool %%f %%f_new 0 1
            cd ..
        ) 
        cd ..
    )
    cd ..
)
  1. To enumerate directories rather than files, you need to use for /D .
  2. Put quotation marks around all paths, like "D:\\Data\\imageA\\20*" , for example. Use the ~ modifier of for variable references to avoid double-quotation.
  3. Remove the cd commands, use absolute paths instead, applying the ~F modifier, like for /D %%m in ("%%~Fy\\*") do ( ... ) .
  4. If you insist of using relative paths (in case the replacetool needs such), use pushd "%%~y" instead of cd %%y and popd instead of cd .. , and change (\\%%y\\*) to ("*") .

Here is the fixed code, using absolute paths:

for /D %%y in ("D:\Data\imageA\20*") do (
    for /D %%m in ("%%~Fy\*") do (
        for /D %%d in ("%%~Fm\*") do (
            for %%f in ("%%~Fd\imageA_*_raster") do replacetool "%%~Ff" "%%~Ff_new" 0 1
        )
    )
)

Here is the code, using relative paths:

for /D %%y in ("D:\Data\imageA\20*") do (
    pushd "%%~y"
    for /D %%m in ("*") do (
        pushd "%%~m"
        for /D %%d in ("*") do (
            pushd "%%~d"
            for %%f in ("imageA_*_raster") do replacetool "%%~f" "%%~f_new" 0 1
            popd
        )
        popd
    )
    popd
)

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