参考:如何使用存档文件名中存档文件夹的日期创建 RAR 存档?
使用引用的批处理文件,我可以为要备份的文件夹制作一个很好的打包文件。
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "FolderToBackup=%1"
rem Get last modification date/time of the folder to backup
rem in region dependent format which is YYYY-MM-DD hh:mm.
for %%I in ("%FolderToBackup%") do set "FolderTimeStamp=%%~tI"
rem Get from this date/time string just the year, month
rem and day of month from the date without the hyphens.
set "FolderTimeStamp=%FolderTimeStamp:~0,4%%FolderTimeStamp:~5,2%%FolderTimeStamp:~8,2%"
rem Compress the folder to backup into a RAR archive file with
rem last modification date of folder used in archive file name.
"%Programw6432%\WinRAR\WinRAR.exe" a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- %FolderTimeStamp%_%FolderToBackup%.rar "%FolderToBackup%"
rem Restore the environment as set before usage of command SETLOCAL at top.
endlocal
我习惯于使用 Total Commander 来管理我的文件。
我将批处理文件配置为TC按钮栏上的一个按钮,按钮设置参数: %s
. 当活动项目是d:\doc\aatemp
TC 中的文件夹时,我按下按钮,TC 调用批处理文件并将正确的文件夹名称传递给打包文件夹的批处理文件。
对于多个文件夹,我想按上述方式进行操作。
所以我用按钮设置参数制作了另一个批处理文件: %L
. TC 在临时文件的文件夹中创建一个列表文件,使用%L
写入此列表文件的选定文件/文件夹的全限定名,并使用此临时列表文件的全名调用批处理文件。
rem @echo off
rem Processing of %L or %WL
REM setlocal EnableExtensions DisableDelayedExpansion
setlocal enabledelayedexpansion
rem for /f "usebackq delims=" %%s in (`type %1`) do echo "%%s"
for /f "usebackq delims=" %%s in (`type %1`) do (
echo "%%s"
rem pause
rem
set FolderToBackup=%%s
echo !FolderToBackup!
REM pause
if "!FolderToBackup:~-1!"=="\" set "FolderToBackup=!FolderToBackup:~0,-1!"
echo !FolderToBackup!
pause
rem Get last modification date/time of the folder to backup
rem in region dependent format which is YYYY-MM-DD hh:mm.
for %%I in ("!FolderToBackup!") do set "FolderTimeStamp=%%~tI"
echo !FolderTimeStamp!
pause
rem Get from this date/time string just the year, month
rem and day of month from the date without the hyphens.
set "FolderTimeStamp=!FolderTimeStamp:~0,4!!FolderTimeStamp:~5,2!!FolderTimeStamp:~8,2!"
echo !FolderTimeStamp!
pause
rem Compress the folder to backup into a RAR archive file with
rem last modification date of folder used in archive file name.
rem "!Programw6432!\WinRAR\WinRAR.exe" a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- !FolderTimeStamp!_!FolderToBackup!.rar !FolderToBackup!
c:\Program Files\WinRAR\WinRAR.exe a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- !FolderTimeStamp!_!FolderToBackup!.rar !FolderToBackup!
)
rem Restore the environment as set before usage of command SETLOCAL at top.
endlocal
我可以pause
在命令行之前使用命令查看我想要的输出WinRAR.exe
。
命令行WinRAR.exe
不能像我想要的那样使用列表文件。