One of my collegue was writing a DOS script that creates directories with date and archives files. The problem she faced is with the DATE command in DOS. DATE command gives date in mm/dd/yyyy format. If we use the same string for creating directory MKDIR command creates 3 directories with mm, dd and yyyy as nested directories.
C:\>echo %DATE%
Wed 03/26/2008
After some search we finally used the Substring methods in DOS to arrive with DATE format mm-dd-yyyy.
C:\>echo %date:~4,2%-%date:~7,2%-%date:~10,4%
03-26-2008
Explanation (%date:~4,2%)
% is used to enclose the expression
:~ is used to start the substring operation
4 is start index
2 is no of characters to extract
2 comments:
thanks for the detailed explanation
This assumes the standard date format in Windows. But that can vary (changed by system admins for one).
Post a Comment