|
Answer» Looking for a way to replace the "/" spit out in the %DATE% command with "_", so that when declaring to create a folder which has the Date Stamp, I dont end up with the primary folder Wed 11, subfolder 22, subfolder 2006, when executing command MD "%DATE%" in my archive to pass daily full backups to of specific data in my batch. For "Wednesday 11/22/2006"
Looking for a way to change the way that DATE is spit out to have say "_" instead of "/" if that is at all possible, or pass the spit data from DATE into a temp location, then replace "/" with "_" before passing it to the MD command to make the directory with Todays Date.
Maybe there is a better way to create this Date or Date/Time Stamped Folder in my batch... ANY SUGGESTIONS? Thanks!!!There are many ways to do this, but since you failed to mention your OS, this may work:
Code: [Select]@echo off for /f "tokens=2-4 delims=/ " %%i in ("%date%") do ( set mm=%%i set dd=%%j set yy=%%k ) set today=%mm%_%dd%_%yy%
You can use %today% where ever you need it. If you need the time, handle it in the same manner.
Good luck. 8-)THANKS Sidewinder .... That did it, as seen below.
C:\ZombieDrop>md %today%
C:\ZombieDrop>dir Volume in DRIVE C has no label. Volume Serial Number is D87E-3A40
Directory of C:\ZombieDrop
11/22/2006 06:06 PM . 11/22/2006 06:06 PM .. 11/22/2006 06:06 PM 11_22_2006 11/22/2006 04:52 PM DailyDrop 11/22/2006 06:04 PM 150 test1.bat 11/22/2006 05:03 PM Wed 11 1 File(s) 150 BYTES 5 Dir(s) 30,160,670,720 bytes free
C:\ZombieDrop>You may want to order your dated directories as %yy%_%mm%_%dd%. It will make comparisons and sorting a lot easier.
That's my second thought today. I've reached my limit. 8-)Do tokens work in the DOS on a boot CD?
If not, then how would this be done without tokens?
thanks, darrylthe date command output is dependent on the date settings of the machine which its configured. for platform independent date manipulations, you can use perl/python languages, if u know them.
here's one in Python for eg (similar for perl) Code: [Select]import time, os mydate = time.strftime("%Y_%m_%d" , time.localtime() ) print mydate print "Making directory %s ", mydate os.mkdir(mydate) #make directory
There's always this:
Code: [Select]set month=%date:~4,2% set day=%date:~7,2% set year=%date:~10,4% echo %month%_%day%_%year% md c:\directory\%month%_%day%_%year%
This works on WIN2K where the %date% is displayed as such: Fri 12/01/2006 If yours simply displays the simple date, such as: 12/01/2006 then the code would be
Code: [Select]set month=%date:~0,2% set day=%date:~3,2% set year=%date:~6,4% echo %month%_%day%_%year% md c:\directory\%month%_%day%_%year%
You could even change AROUND the %month% %day% %year% in whatever order you prefer
|