0

We have a file share that has a directory containing all of our build version direcotries named like this

WebApp_20140702.1 first number being date second number being the build count for that date

these are then contained in the following directory

\\server\share\product\

What i need to do from a virtual machine is create a batch file that can check the target location on my vm ie. c:\product\ see if it has the latest version from the network share either by comparing the file names or dates, then copy the new version and delete the old if necessary.

So far i can copy the folder over using xcopy but that's about the extent of my dos/batch file knowledge iv had a look around for a while but haven't been able to see anything that i can use

This is what i have so far, as you can see though i dont know how to do the comparison between the two directories as explained above.

xcopy "\\server\share\webapp" "c:\users\username\desktop\webapp" /E /K

I did try to use just /D at the end and just copying the directories from \\server\share\product\ that had a later date than the target but it ended up just copying the whole directory.

EDIT : to make my self clear

i need to find out if i have the latest sub directory but no matter what i do it always copies all the sub directories from \\server\share\product\

ie. the \\server\share\WebApp directory will have the following sub dirs

..\WebApp_20140628.1\
..\WebApp_20140628.2\
..\WebApp_20140703.1\

and my vm will have the directory

c:\product\WebApp_20140628.2\

Now i need to be able to go into the file share see that it has a more up to date subdirectory i need to copy that directory to my vm and then delete the older one from my vm so i would then have

c:\product\WebApp_20140703.1\

John DOE
  • 400
  • 1
  • 3
  • 18
Sirk
  • 1,547
  • 2
  • 12
  • 18
  • There are dozens of questions here previously about doing a similar task (copying files if they are newer/older than something), all of which are answered by using `robocopy`. Typing `robocopy /?` from a command prompt or visiting [MS Technet](http://technet.microsoft.com/en-us/library/cc733145.aspx) should help. (Of course, the proper way to do this would be to have your files checked into a version control system, and then the most recent version would always be available to check out from the repository whenever and wherever it was needed.) – Ken White Jul 03 '14 at 14:13
  • Hi Ken thanks for the comment, i had a look at robocopy but couldn't find a way to do what i want, i have updated my question to give an example of what i need to do – Sirk Jul 03 '14 at 15:25

1 Answers1

0

OK i eventually found another question that wanted to do a similar thing and the answer worked exactly as i wanted it

Question can be found here: How to get the most recent file using a batch script in windows

i had to use xcopy instead of the copy used in the answer for the above question. here is my solution as well in case anyone needs something similar (z is the mapped version of the network share i talk about in my question)

pushd "z:\WebApp\" for /f "tokens=*" %%a in ('dir/b /od') do set newest=%%a xcopy /e /k "%newest%" "c:\product\" popd

im not sure if i actually need the popd command as i believe it just goes back to the directory set in the pushd command

Community
  • 1
  • 1
Sirk
  • 1,547
  • 2
  • 12
  • 18