for /D %%A in () do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%A.zip" -xr!.bat "%%A" -r -x!*.xls
The above batch will automatically zip the files in a directory.. While zipping I want to append date and time in a format (YYYYMMDD.HHMMSS).. For example,say the folder name is "University".If I run the batch file, the final zip name should create as "University_YYYYMMDD.HHMMSS.zip"..
On a Microsoft Windows system, you can obtain the current date using the date /t command (the /t option prevents the command from prompting for a change to the the date) or by using echo %date% to display the contents of the date environment variable.
Type date without parameters to display the current date setting and a prompt for a new date. Press Enter to keep the same date. If you provide a date in the format MM-DD-YY, the system date is set to that date. When specifying a two-digit year, the digits 00-99 correspond to the years 1980-2099.
This code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "fullstamp=%YYYY%%MM%%DD%.%HH%%Min%%Sec%"
for /D %%A in (*) do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%A_%fullstamp%.zip" -xr!.bat "%%A" -r -x!*.xls
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With