tags:

views:

378

answers:

4

I'm trying to make a script that will make a copy of a folder (in Windows) every day for the last 7 days. On the 8th day I want it to take the oldest copy and overwrite it and so on and so forth so at any one time I'll have a 7 day "history" of the folder.

Now I've done that previously in Linux simply by telling a daily bash script to copy the folder to "/home/whatever-date +%u'".

date +%u by the way outputs the day of the week. 1 for Mon, 2 for Tue, etc.

In comparison the DOS date command is completely retarded. Is there an easy way to get the day of the week (numeric value) in a DOS batch file or should I just give up and write this in Java?

A: 

Short answer: Not that I know, no you can't get the day of the week. You better use Java, as mentioned.

Long answer: You can have a look there to get started with handling files from a given given laps (a week/7 days), and use at or the scheduler service to run it every sunday (on a Windows machine).

Hope this helps.

EDIT: I see you want to run this everyday and have a different behavior in the 8th day. You can always leave a flag in the directory (hidden file called "______day", containing the iteration #) and check it when you begin the copy job.
If it's 1 to 6, increment the content, if it's 7, do your master copy and put 1 in the file.
Something along those lines.

Jay
A: 

The DATE environment variable (%DATE%) returns the day of the week (MON, TUE, WED, ...). Seems like it would be good enough.

JRL
This reflects your localisation settings. Here, all I get is YYYY-MM-DD, so it won't work everywhere.
Jay
+1  A: 

From this page:

@echo off
Echo.|Command /C Date>DOW
set /p today=<DOW
set DOW=%today:~16,3%
xcopy "C:\Source\*.*" "C:\Dest\%DOW%"

This will backup into subfolders called Sun, Mon, Tue ... Sat. You'll need to create those folders yourself, or edit the script to create them.

EDIT: Poor description of what this does.

Kris Peters
Also it fails miserably on 64-bit Windows due to `command.com` lacking.
Joey
A: 
Rodney Beede