from:
http://hi.baidu.com/guicomeon/item/c0957c373972fbc52f8ec26e
先说明一点,要注意区分当前所使用的系统,中文系统和英文系统是有区别的。
@echo off
call :getFileName
7z a D:\Projects\%varname% D:\Projects\TestProject\*
goto :end
:getFileName
set vardate=%date:~6,4%-%date:~0,2%-%date:~3,2%
set vartime=%time:~0,2%-%time:~3,2%
set varname=[%vardate%-%vartime%].7z
:end
=========================================================================
将上述绿色部分保存到记事本中,并重命名为*.bat即可。对于中文系统,须将
set vardate=%date:~6,4%-%date:~0,2%-%date:~3,2%
替换为
set vardate=%date:~0,4%-%date:~5,2%-%date:~8,2%
其他不变。
set vardate=%date:~0,4%-%date:~5,2%-%date:~8,2% echo %vardate% set varname="备份_%vardate%.zip" echo %varname% pause
zip打包时,文件名中别用空格
-