|
Answer» Hi all
I run a daily batch file to make backups but do not want to overwrite the previous day's backup.
Answer for me is to let the batch file make a directory with "date" as directory, i.e.
set var=%date%
..... now var is set to today's date - OK so far ...
I now want to make a directory using "var" as the variable, i.e
md %var%
but this gives me a syntax error.
How do I make a directory in the batch file using "var"
Mike_KIf your system date format has forward SLASHES / as the separators you need to get 'em out because that character is illegal in a WINDOWS file or directory name.
e.g. replace with hyphens
Code: [Select]set var=%date:/=-% or spaces
Code: [Select]set var=%date:/= % or dots
Code: [Select]set var=%date:/=.% (or whatever legal character or characters you like, put it or them to the right of the equals sign)
or nothing (nuke 'em)
Code: [Select]set var=%date:/=% Thx Dias
I've used yur suggestion with a bit of other code ....
set today=%date:/=_%
echo off echo THE CURRENT DATE IS (day/month/year) : %DATE%
mkdir "%today%" cd "%today%" echo . echo CHECKING DESTINATION FOLDER IS TODAY'S MONTH/DATE echo . echo on (allows user to check destination folder by seeing the COMMAND prompt) echo off echo . pause
Xcopy C:\Backup_\*.* /E/Y/I
As the days move on I will get a series of backup folders ...
07_04_2009 08_04_2009 09_04_2009 ..... etc.
Many thanks
Mike_K
|