Archive Name And Parameters Game
Raving Rabbids 2 Wii Download.
I am compressing files using on the command line. Since we archive on a daily basis, I am trying to add date and time to these files so that a new one is auto generated every time. Adobe Premiere Pro Cs4 Windows 7 32 Bit more. I use the following to generate a file name. Copy paste it to your command line and you should see a filename with a Date and Time component. Echo Archive_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.zip Output Archive_20111011_ 93609.zip However, my issue is AM vs PM. The AM time stamp gives me time 9 (with a leading blank space) vs. 10 naturally taking up the two spaces.
The dialog contains the following items: Destination archive name. Enter the name manually or press the 'Browse' button to browse for the archive name. Since we archive on a daily basis. Batch command date and time in file name. And a file name with a space in it would be treated like two parameters.


I guess my issue will extend to the first nine days, first 9 months, etc. How do I fix this so that leading zeroes are included instead of leading blank spaces so I get Archive_20109.zip? As Vicky already pointed out,%DATE% and%TIME% return the current date and time using the short date and time formats that are fully (endlessly) customizable.
One user may configure its system to return Fri040811 08.03PM while another user may choose 20:30. It's a complete nightmare for a BAT programmer.
Changing the format to a firm format may fix the problem, provided you restore back the previous format before leaving the BAT file. But it may be subject to nasty race conditions and complicate recovery in cancelled BAT files. Fortunately, there is an alternative. You may use WMIC, instead. WMIC Path Win32_LocalTime Get Day,Hour,Minute,Month,Second,Year /Format:table returns the date and time in a invariable way. Very convenient to directly parse it with a FOR /F command. So, putting the pieces together, try this as a starting point.
SETLOCAL enabledelayedexpansion FOR /F 'skip=1 tokens=1-6'%%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO ( SET /A FD=%%F*1000000+%%D*100+%%A SET /A FT=10000+%%B*100+%%C SET FT=!FT:~-4! ECHO Archive_!FD!_!FT!zip ).
You can add leading zeroes to a variable (value up to 99) like this in batch: IF 1%Var% LSS 100 SET Var=0%Var% So you'd need to parse your date and time components out into separate variables, treat them all like this, then concatenate them back together to create the file name. However, your underlying method for parsing date and time is dependent on system locale settings.
If you're happy for your code not to be portable to other machines, that's probably fine, but if you expect it to work in different international contexts then you'll need a different approach, for example by reading out the registry settings: HKEY_CURRENT_USER Control Panel International iDate HKEY_CURRENT_USER Control Panel International iTime HKEY_CURRENT_USER Control Panel International iTLZero (That last one controls whether there is a leading zero on times, but not dates as far as I know). From the answer above, I have made a ready-to-use function. Validated with french local settings.:::::::: PROGRAM:::::::::: call:genname 'my file 1.txt' echo '%newname%' call:genname 'my file 2.doc' echo '%newname%' echo.&pause&goto:eof:::::::: FUNCTIONS::::::::::genname set d1=%date:~-4,4% set d2=%date:~-10,2% set d3=%date:~-7,2% set t1=%time:~0,2%::if '%t1:~0,1%' equ ' ' set t1=0%t1:~1,1% set t1=%t1: =0% set t2=%time:~3,2% set t3=%time:~6,2% set filename=%~1 set newname=%d1%%d2%%d3%_%t1%%t2%%t3%-%filename% goto:eof.