0

I tried to write a script that copies modified files from my development environment to a desktop folder, but it copies all of the files, not just the modified ones. This is the script:

set codeFolder=C:\Dev\tsg-bto-apps-lt-pc-trunk

FOR /F "TOKENS=1 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET dayOfWeek=%%A
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET dd=%%B
FOR /F "TOKENS=1,2,3 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%C
FOR /F "TOKENS=1,2,3,4 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET yyyy=%%D

SET today=%dd%-%mm%-%yyyy%

Xcopy /Y /D:%today% /I %codeFolder%\bin C:\Users\sheaffer\Desktop\testFolder  

The method is as follows:

  1. Get today's date (I used the method that appears in the second answer in the following link: Windows batch: formatted date into variable).

  2. Use Xcopy with the /D flag (there is an example in the following link: http://www.windows-commandline.com/xcopy-command-syntax-examples/)

I can't see what I am doing wrong. The result is that all of the files in my bin folder are copied, and not just files that have been modified today. When I run my script, the command that is generated is:

Xcopy /Y /D:04-11-15 /I C:\Dev\tsg-bto-apps-lt-pc-trunk\bin C:\Users\sheaffer\Desktop\testFolder

Please help me understand my mistake. Thanks.

Community
  • 1
  • 1
Roy
  • 35
  • 4
  • 1
    If you don't insist on using xcopy, I'd recommend using robocopy. – Filburt Nov 04 '15 at 12:15
  • @Filburt Thanks. I took your advice and rewrote the script using robocopy. It works, and the new script is simpler because I can use `/maxage:1` and avoid string/date manipulation. I am still curious about why the script I posted doesn't work. – Roy Nov 04 '15 at 13:20

2 Answers2

0

I took Filburt's advice and used robocopy instead of xcopy and it works. The new script is simpler because I can use /maxage:1 and avoid string/date manipulation.

set codeFolder=C:\Dev\tsg-bto-apps-lt-pc-trunk

robocopy %codeFolder%\bin C:\Users\sheaffer\Desktop\testFolder /MAXAGE:1
Roy
  • 35
  • 4
0

The help for xcopy says the /D date format is m-d-y and you have your date in d-m-y format. You're saying copy all files changed on or after Apr 11, 2015. Also robocopy is better than xcopy . Really long path names that trip up xcopy

JJF
  • 2,681
  • 2
  • 18
  • 31