Search code examples
batch-filewindows-7sequential

Windows Batch Files: copy sequential files


Just a quick foreword: I'm an artist, and only have a small amount of programming understanding, and I just started learning windows batch files a couple hours ago.

So, at my school, when we render our files in Maya, we have to do it on a local drive, and we use several computers to speed up this process. This creates hundreds of images across multiple computers. My plan was to create a batch file that copies the images (as they are finished) over the network to a single drive so managing my rendered images is easier.

I'm using a for loop to go through file names (in this case, BallTest_xxxx.exr), and I can print out the name just fine; but, when I try setting the filename to a variable in the loop, it ends up printing out nothing.

Where I have "echo.%asdf%, I want that to be where it reads the file, and from there, checks to see if the render is finished (I have a couple of ideas for the latter, but for now, I'd just like some insight on what I'd need to do to make the first part work.) I can see in the results, that when I try to set asdf as the filename, it gives me BallTest_000%x.exr, which I know isn't right.

set "filename=BallTest_"
set "extension=.exr"

for /l %%x in (1, 1, 3) do (
    if %%x lss 10 (
        set asdf=%filename%000%%x%extension%
        echo.%filename%000%%x%extension%
        echo.%asdf%
    )
)

pause

Thanks in advance,

George


Solution

  • may be this is what you are looking for:

    @echo off
    set "filename=BallTest_"
    set "extension=.exr"
    setlocal enableDelayedExpansion
    for /l %%x in (1, 1, 3) do (
        if %%x lss 10 (
            set asdf=%filename%000%%x%extension%
            echo.%filename%000%%x%extension%
            echo.!asdf!
        )
    )
    endlocal
    pause
    

    Delayed expansion is a confusing thing for newbies in batch files. More info you can find here and here