0

How can I move/copy a file from D:\WindowsImageBackup\ to D:\Included\ if it's a Sunday or delete D:\Included\ if it's any other day?

The scenario is: An automatic backup to a remote server runs once a day. I want a certain file to be backed up only once a week, on a Sunday (it's the Windows image backup). I have excluded the folder where the file lives (D:\WindowsImageBackup).

Marcus
  • 9,011
  • 10
  • 45
  • 65
  • 2
    Why not use a Windows scheduled task for this? It's much easier to schedule, and you can have it run right before the automatic backup is supposed to run. A scheduled task can run at an exact time, and can be easily configured to run only one day (or all other 6 days) extremely easily. This would make it a matter of writing two simple batch files (one to be run on Sunday, the other to run every other day) and scheduling those batch files to be run. – Ken White Dec 04 '12 at 02:22

1 Answers1

1

You can do it pretty easily:

setlocal enableextensions enabledelayedexpansion
set dow=%date:~0,3%
if "%dow%" equ "Sun" xcopy /y "D:\WindowsImageBackup\*.* "D:\Included\" & goto eof
echo del "D:\Included\*.*" /y
:eof

Note that this works only if your system language is English, as it does a literal comparison of the day part of Date against the value Sun, and of course isn't localized.

Also, see my comment to your question about this perhaps being better for a scheduled task (as errors would stop it and write to the Event Log).

Ken White
  • 123,280
  • 14
  • 225
  • 444