Discussion Locked

MS-DOS Batch Files

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I want to create a batch file that automates xcopy in DOS. I want to use the system date to create a directory with today's date and xcopy files into it. How do I use the system date to create a directory? I have done a complete script in UNIX and it works great. Any help would be appreciated. Thanks, John

2 replies

by sean reed

According to "MS-DOS Batch File Programming 2nd Edition", chances are the best way would be to somehow save the output of DATE to a system variable. Then, once it's been saved, just issue an MD (or MKDIR) command specifieing whatever system variable you stored the date in.

For instance:
@echo off
date > %date%
md %date%
THEN your various xcopy commands.

by jbridges

This works for me.

:Begin
:: Extract the date and apply it to variables.

for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set DayOfWeek=%%i
set Month=%%j
set Day=%%k
set Year=%%l
set Date=%%i %%j/%%k/%%l
)
rem scopyc:\hyperi~1\*.* E:\recover\cldate\Daily Backup /o /a /s
scopy c:\hyperi~1\*.* E:\recover\hyperbak\Daily /s

Exit
pause

This discussion is closed to new replies.