3

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?

Manos Dilaverakis
  • 5,849
  • 4
  • 31
  • 57
  • I do not know the answer to your problem. But I would like to suggest that your question might also be applicable to superuser.com or serverfault.com, because it is not strictly programming related. – Hauke Sep 08 '09 at 12:44

4 Answers4

1

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.

Strabbi
  • 213
  • 3
  • 7
1

Better variation of Kris without the temporary file

set DOW=%date:~16,3%<br>
xcopy "C:\Source\*.*" "C:\Dest\%DOW%"
Taryn
  • 242,637
  • 56
  • 362
  • 405
0

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.

Community
  • 1
  • 1
Jay
  • 1,635
  • 16
  • 14
0

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

JRL
  • 76,767
  • 18
  • 98
  • 146
  • 2
    This reflects your localisation settings. Here, all I get is YYYY-MM-DD, so it won't work everywhere. – Jay Sep 08 '09 at 16:24