用于压缩当天 XML 个文件的批处理文件

Batch File for zipping Current day XML files

我必须执行一项任务,在 //Traning/Biz 中有一些 xml 文件以当天为前缀,例如 201504140157034_{hgds}.xml。 我需要创建一个批处理脚本,它可以在同一网络文件夹中创建一个具有当前日期名称的 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..."

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%-Zipz.exe" a -tzip -pSomePassword "%zipFileName%" "%drive%\*.*"

省略 -tzip 以获得本机 7z 存档而不是 winzip。

在此处查看 7z 的示例:http://www.dotnetperls.com/7-zip-examples