我必须在// Traning / Biz中执行一项任务,其中包含一些带有前缀命名当前日期的xml文件,例如 201504140157034_ {hgds} .xml 。 我需要创建一个Batch脚本,它可以在同一个网络文件夹中创建一个当前日期名称的zip文件,并将所有当前日期文件压缩到该文件。
我找到了以下代码, 请帮助我做到这一点
提前致谢:)
@echo off
:: variables
set drive=G:\Backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"
echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"
echo ### Backing up email and address book (Outlook Express)...
%backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"
echo ### Backing up email and contacts (MS Outlook)...
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"
echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"
:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."
答案 0 :(得分:1)
winzip和7z都具有命令行功能。我建议如果您还没有安装,请下载7z(因为它是免费的)。 然后你只需要知道如何复制正确的xml文件,然后再将其全部压缩。
rem to get the date in yyyyMMdd format
for /f %%a in ('wmic os get LocalDateTime ^| findstr [0-9]') do set dt=%%a
set dt=%dt:~0,8%
%backupcmd% \\Traning\Biz\%dt%*.xml "%drive%\XML"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip -pSomePassword "%zipFileName%" "%drive%\*.*"
省略-tzip以获取原生的7z存档而不是winzip。
在这里查看7z的示例:http://www.dotnetperls.com/7-zip-examples