Backing up a folder in the last 7 days using a DOS batch file

I am trying to make a script that will make a copy of a folder (on Windows) every day for the past 7 days. On day 8, I want him to take the oldest copy and overwrite it, etc. And so on, so at any time I will have a 7-day "history" of the folder.

Now I did this earlier on Linux, just telling the daily bash script to copy the folder to "/ home / whatever-date +% u".

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

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

+3
source share
4 answers

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 is a backup to subfolders called Sun, Mon, Tue ... Sat. You will need to create these folders yourself or edit the script to create them.

EDIT: A poor description of what this does.

+1
source

Chris's best change without a temporary file

set DOW=%date:~16,3%<br>
xcopy "C:\Source\*.*" "C:\Dest\%DOW%"
+1
source

: , , . Java, .

: , (/7 ), ( Windows).

, .

EDIT: , 8- . ( ______day), #) .
1 6, , 7, 1 .
- .

0

DATE (% DATE%) (MON, TUE, WED,...). , .

0

Source: https://habr.com/ru/post/1717124/


All Articles