How can I use Xcopy to copy files changed yesterday?

March 9, 2017 at 10:13:35
Specs: Windows 7
Found a discussion on this but it was closed. It didn't have the solution I needed, but if anyone else falls in here from their search, and is in a similar situation, where the archive bit cannot be used for xcopy, I found a solution by using two small batch files. Task Scheduler runs the first the evening of the day before and sets the current date. The next uses that date to perform the xcopy.

for /F "tokens=1* delims= " %%A in ('DATE/T') do set SYSDATE=%%B
set DATE_MM=%SYSDATE:~0,2%
set DATE_DD=%SYSDATE:~3,2%
echo %DATE_MM_DD_YYYY% > Yesterday.txt

and then I run the actual xcopy batch file:

set /p "dt=" < yesterday.txt
xcopy c:\users\billh\documents\test c:\users\billh\documents\test1 /D:%dt%

Code for setting the date is from: Thanks to summerson83.

See More: How can I use Xcopy to copy files changed yesterday?

Report •

March 9, 2017 at 14:08:27
Or you could just use robocopy with the minage and maxage switches.

A much more versatile command than xcopy, and more robust.

Report •

March 9, 2017 at 15:27:47
Or use XCOPY /M if this a pseudo backup solution.
Or FORFILES if you don't want to figure out yesterday's date.

How To Ask Questions The Smart Way

Report •

March 10, 2017 at 02:48:20
The /M switch to xcopy relies upon the archive bit, which the OP explicitly excluded from their solution.

Report •
Related Solutions

Ask Question