0

I am using the following Robocopy command:

robocopy z:\ c:\Testing\ TestFiles.zip

The issue is that it keeps copying some file listed under * EXTRA File but this file is already in the destination.

I only want robocopy to copy over a file if it is a newer version (date created is different)

Only if TestFiles.zip has a newer date created.

To fix this I have tried using /xo meaning exclude older files. With no luck. This is what happens every time when I execute the script once a minute has passed.

enter image description here

  • Note, that `robocopy` does not care about the creation date, it only regards the last modification date! – aschipfl Mar 20 '19 at 14:34
  • When executing `robocopy` you should get different informations about the copying-process like the applied options. What does it show you? – Gmork Mar 20 '19 at 14:34
  • @Gmork Options : /DCOPY:DA /COPY:DAT /XO /R:1000000 /W:30 –  Mar 20 '19 at 14:35
  • Using the same options does everything right for me. Do you modify the file before executing robocopy every minute? – Gmork Mar 20 '19 at 15:11
  • No of course not, is there a way to stop the extra files and new files unless the date created changes? Is looking at date modification/creation somehow possible with robocopy –  Mar 20 '19 at 15:32
  • `robocopy` only copies modified files - and that by default. – Gmork Mar 20 '19 at 15:43
  • You could perhaps execute the command twice and print the protocols in your question, but atm I do not know what could be the cause for that. – Gmork Mar 20 '19 at 15:50
  • What do you mean execute the command twice, how would this help? –  Mar 20 '19 at 16:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/190378/discussion-between-gmork-and-jackson-mills). – Gmork Mar 20 '19 at 16:29
  • So, you mean that there is a file called `TestFiles.zip` in `C:\Testing` and you need to override this **only** if the one in ``Z:\`` has newer modified date? If yes, then try this complicated solution: `for /F "tokens=1 eol=" %%A IN ('dir /O-N /A-D "C:\Testing\TestFiles.zip" 2^>nul') do for /F "tokens=1-3 delims=/" %%B IN ("%%A") do set "var1=%%D%%C%%B"` and under that a line with `for /F "tokens=1 eol=" %%A IN ('dir /O-N /A-D "Z:\TestFiles.zip" 2^>nul') do for /F "tokens=1-3 delims=/" %%B IN ("%%A") do set "var2=%%D%%C%%B"`. – double-beep Mar 21 '19 at 16:28
  • And a third line: `if %var1% LSS %var2% move "Z:\TestingFiles.zip" "C:\Testing"`. It should work, although I am searching for a more simplified way. Please let me know if these ways worked for you, so I can post them as answers. – double-beep Mar 21 '19 at 18:32
  • Yes perfect! No issues thanks! –  Mar 21 '19 at 18:33
  • @JacksonMills if possible, accept an answer as per https://stackoverflow.com/help/someone-answers. – double-beep Mar 25 '19 at 05:24

2 Answers2

0

It looks like the solution to your problem may be here -> How do I compare timestamps of files in a batch script?

If we think about the issue...we only want to execute your code if the timestamp of the current file is newer then the older one so here is what the pseudo code would look like, you just need to translate it into batch code.

If current file version is newer then other file version (
    robocopy z:\ c:\Testing\ TestFiles.zip
)
Zach Pedigo
  • 396
  • 2
  • 9
0

My suggested solution, as mentioned in comments is as follows:

for /F "tokens=1 eol=" %%A IN ('dir /O-N /A-D "C:\Testing\TestFiles.zip" 2^>nul') do (
    for /F "tokens=1-3 delims=/" %%B IN ("%%A") do set "dt1=%%D%%C%%B"
)

for /F "tokens=1 eol=" %%E IN ('dir /O-N /A-D "Z:\TestFiles.zip" 2^>nul') do (
    for /F "tokens=1-3 delims=/" %%F IN ("%%E") do set "dt2=%%H%%G%%F"
)

if %var1% LSS %var2% (move "Z:\TestingFiles.zip" "C:\Testing")

This code, searches the last modification date of the files you want and compare them. If the one in C:\Testing is smaller, then more the file TestingFiles.zip to it.

double-beep
  • 5,031
  • 17
  • 33
  • 41