Thursday, May 14, 2009

Creating directories with date using batch files in XP

This is how you create directories with todays date using a batch file for xp/win server command prompt. Useful when you are doing backups

[sourcecode language='shell']
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%A%%B%%C
md %var%
cd R:\MACHINE PROGRAMS\%var%\
[/sourcecode]

Copy and paste the code directly, any space where it's not suppose to be can cause the script to break (like a space between the = and %%A%%B%%C.
To use the date just use the variable %var%.

No comments:

Post a Comment