1

I need to copy files from recent build folder to another folder used for testing. I'm having a hard time getting the name of the most recent build folder.

My current attempt is this:

@for /D %%i in ('dir e:\builds\projectA\* /O:D') do set target=%%i
echo %target%
xcopy "%target%\*.*" \\devbox\projectA /y /s 

I was hoping target would be the newly created folder from which I could then copy the files from. However, when I echo target to the console it just says:

/O:D'

Does anyone know how I can get this to work (or know of an alternative)?

2 Answers 2

5

Replace the /D with /F and add /B to the bracketed dir command.

@for /F %%i in ('dir e:\builds\projectA\* /O:D /B') do set target=%%i
echo %target%
xcopy "%target%\*.*" \\devbox\projectA /y /s
1
  • 1
    you might also want to add a SetLocal and EndLocal at the start and end of your script so the target variable doesn't persist. good luck!
    – Mike
    Commented May 11, 2009 at 15:21
0
pushd E:\builds\projectA
for /f "delims=" %%d in ('dir /b /a:d /o:d') do @echo %%d>latest.txt
for /f "delims=" %%l in (latest.txt) do xcopy "%%l\*.*" \\devbox\projectA /y /s
del latest.txt
popd

Not the answer you're looking for? Browse other questions tagged or ask your own question.