tags:

views:

79

answers:

2

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)?

A: 
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
Tomalak
+5  A: 

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
Vicky
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
worked perfectly. thanks.
Sailing Judo