Question

I'm trying to write a script that copies a folder every week night. I would like it to create a folder each night in the destination directory.

So I'm trying to make a script that copies "C:\logs" to "I:\logs\today's date"

So the destination folder should look like this

"I:\logs\Monday_1272014" then the next night it should look like this "I:\logs\Tuesday_1282014"

and so on for each weekday. I'm not sure if I'm making sense, but any help would be appreciated.

So far I have this for the Robocopy script: robocopy "E:\Batch Files" "I:\Backups\Monday" /MIR

But that would just create a folder named Monday. Any help would be greatly appreciated. Also, it does not have to be robocopy. I just use that because it's the only one I know. I wouldn't mind learning how to do it as a batch file or VB Script.

Thanks!

Was it helpful?

Solution

The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%"

Alter the order of %yyyy% and %mm% and %dd% to suit you and then you can add the variable to Robocopy:

robocopy "E:\Batch Files" "I:\Backups\%datestamp%" /MIR

OTHER TIPS

@ECHO OFF &SETLOCAL enableDelayedExpansion
FOR %%a IN (Monday Tuesday Wednesday Thursday Friday Saturday Sunday) DO SET /a cnt+=1&SET "DOW!cnt!=%%a"
FOR /f "tokens=1-4" %%a in ('wmic path win32_currenttime get Day^,Month^,Year^,DayOfWeek^|findstr /v "^$"') DO (
    IF %%a LEQ 9 (SET "Day=0%%a") ELSE SET "Day=%%a"
    IF %%c LEQ 9 (SET "Month=0%%c") ELSE SET "Month=%%c"
    SET "Year=%%d"
    SET "DayOfWeek=%%b"
)
ECHO(ROBOCOPY "E:\Batch Files" "I:\logs\!DOW%DayOfWeek%!_%Day%%Month%%Year%" /MIR

This doesn't work in XP Home.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top