Need to use xcopy with the /d:mmddyyy

September 9, 2011 at 08:06:48
Specs: Windows XP
I need to use xcopy /D: 09092011 date switch. How do I have the date increment by 1 day. --Without typing it in /:09102011.


See More: Need to use xcopy with the /d:mmddyyy

Report •

September 12, 2011 at 08:48:21
You will have to turn the dates into variables.

First you should output the date into a file like this:

date /t >> c:\tmpdate.txt

Then you should load the contents of that file into a variable so that you can start modifying it like this:

set /p timevar=<tmpdate.txt

This value comes out like Mon 09/12/2011, but we only need the last 10 characters. Get the last 10 characters (mm/dd/yyyy) from that value like this:

set timevar=%timevar:~-11%

Now just remove the slashes like this:

set timevar=%timevar:/=%

At this point, timevar equals an 8 digit date representation with no slashes, just like xcopy likes it. So from here, you just need to break up the variable for modification. To do that, we can split it into three new variables representing day, month, year, like this:

set timevarfront=%timevar:~0,4% (gets month and day as 4 character string)

set timevarmonth=%timevarfront:~0,2% (gets month from 4 character string)

set timevarday=%timevarfront:~-2% (gets day from 4 character string)

set timevaryear=%timevar:~-4% (gets year from original timevar variable)

Now comes the increment you wanted:

set /a timevarday=%timevarday% + 1

Now, you can call the variable in your xcopy command like this:

xcopy /D: %timevarmonth%%timevarday%%timevaryear%

Report •
Related Solutions

Ask Question