1

So https://technet.microsoft.com/en-us/library/cc771254.aspx describes the /d parameter of the xcopy command as allowing you to only copy the source file changed on or after the specified date, so I wanted to use the underneath command but with the current date. Does anyone know how to get the current date in batch and properly format it within the below command?

xcopy /d [:MM-DD-YYYY]
pHorseSpec
  • 1,246
  • 5
  • 19
  • 48
  • 2
    Might be helpful : How to get current datetime on Windows command line, in a suitable format for using in a filename? http://stackoverflow.com/q/203090/4291215 – loadingnow Sep 29 '15 at 14:12

1 Answers1

2
@echo off
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set yyyy=%ldt:~0,4%
set mm=%ldt:~4,2%
set dd=%ldt:~6,2%

echo xcopy source destination /D:%mm%-%dd%-%yyyy% /L

remove echo in front of xcopy, edit source and destination. /L is to list only, no destructive command.

Paul
  • 2,620
  • 2
  • 17
  • 27
  • This code gives me an invalid `/d` parameter. When I echo `%mm%-%dd%-%yyyy%`, I get `~4,2-~6,2-~0,4`, not today's date. – pHorseSpec Oct 02 '15 at 14:22
  • It works when I use only your above 5 lines. When I insert it into my batch, it isn't working. I'll see why – pHorseSpec Oct 02 '15 at 14:32