3

I'm looking to create a Visual Studio post build script that uses xcopy or similar to copy the latest build files into another directory. I've created a batch script that returns the most recent filename, but haven't found a solution to find the most recent folder (latest build) within the builds folder.

Any advice or potentially another method to modify the build definition to output to two directories?

Path for each build is similar to below:

\server\x\Builds\x\xxx20141212.6\

\server\x\Builds\x\xxx20141212.5\

so I need some way to find and copy the latest folder (in this case xxx20141212.6).

Thanks :)

UPDATE:

Have managed to get it working :) Script posted below. It finds the most recent file OR folder based on date modified. In my case, there are only folders so this is fine.

@echo off

REM Find the directory containing the latest build

for /f "delims=" %%x in ('dir "\server1\x\x\" /od /b') do set latest=%%x

REM Mirror the latest folder onto server

robocopy "\server1\x\x\%latest%" "\server2\x\x\x" /MIR

The "delims=" allows it to find file names containing spaces. So with a folder "New Folder" it would return "New Folder" rather than just "New".

  • [Edit your question](http://stackoverflow.com/posts/27473932/edit) and post here your batch script _that returns the most recent filename_; finding _the most recent folder_ might be similar task? – JosefZ Dec 14 '14 at 21:54
  • What is your definition of "most recent folder"/ "latest build"? Time stamp on folder? Build date/version within name? Time stamp of files within folder? – dbenham Dec 14 '14 at 21:55
  • Adding `/ad` or `/a-d` to the `dir` command will select only folders, or only non-folders respectively. – TripeHound Jan 13 '15 at 12:54

0 Answers0