简体   繁体   English

如何将批处理文件与Total Commander GUI选定的文件/目录集成?

[英]How to integrate batch file with Total Commander GUI selected files / directories?

Reference: How to create a RAR archive with date of the archived folder in archive file name? 参考: 如何用存档文件名中的存档文件夹的日期创建RAR存档?

With the referenced batch file I can make a good packed file for the folder I want to backup. 使用引用的批处理文件,我可以为要备份的文件夹制作一个打包好的文件。

@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

I am used to manage my files with Total Commander. 我习惯用Total Commander管理我的文件。

I configured the batch file to be a button on the button bar of TC with the button setting Parameters: %s . 我将批处理文件配置为TC的按钮栏上的按钮,按钮设置为Parameters: %s When the active item is a folder like d:\\doc\\aatemp in TC, I press the button and TC calls the batch file and passes the correct folder name to the batch file which packs the folder. 当活动项目是TC中的d:\\doc\\aatemp类的文件夹时,我按按钮,TC调用批处理文件,并将正确的文件夹名称传递给打包该文件夹的批处理文件。

For more than one folder I want to do as above. 对于一个以上的文件夹,我想如上所述进行。

So I made another batch file with the button setting Parameters: %L . 因此,我使用按钮设置Parameters: %L制作了另一个批处理文件。 TC creates a list file in folder for temporary files on using %L with full qualified names of selected files / folders written into this list file and calls the batch file with full name of this temporary list file. 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

I can see with command pause the output as I want before the command line with WinRAR.exe . 我可以在WinRAR.exe的命令行之前通过命令pause所需的输出。

The command line with WinRAR.exe cannot work with the list file as I want it. WinRAR.exe的命令行无法与列表文件一起使用(如我所愿)。

This extended version of the batch file can be called for example by Total Commander with first argument being an absolute or even a relative folder path not ending or ending with a backslash as well as name of an existing list file with absolute or relative file path. 批处理文件的这种扩展版本可以由Total Commander调用,例如第一个参数是绝对或什至相对的文件夹路径,不以反斜杠结尾或以反斜杠结尾,以及具有绝对或相对文件路径的现有列表文件的名称。

@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "FolderToBackup="
if "%~1" == "" goto ErrorArg
set "FolderToBackup=%~f1"

rem Does the argument string not end with a backslash for a folder path?
if not "%FolderToBackup:~-1%" == "\" goto IsFolder

rem The argument string is a folder path.
rem Does the specified folder not exist?
if not exist "%FolderToBackup%" goto ErrorArg

rem The specified folder exists and is archived now on not being a root folder.
call :BackupFolder
goto EndBatch

:IsFolder
rem Does the argument without trailing backslash not specify a folder?
if not exist "%FolderToBackup%\" goto ExistsFile

rem The argument is a folder path.
rem This folder is archived now on not being a root folder.
call :BackupFolder
goto EndBatch

:ExistsFile
rem The argument string is definitely not a folder path.
rem Does the argument string not specify an existing file?
if not exist "%FolderToBackup%" goto ErrorArg

rem The argument string specifies a file which is hopefully a list file.
set "ListFile=%FolderToBackup%"
for /F "usebackq eol=| delims=" %%I in ("%ListFile%") do (
    set "FolderToBackup=%%~I"
    call :BackupFolder
)
goto EndBatch

:BackupFolder
rem Remove the backslash at end of folder path if there is one at all.
if "%FolderToBackup:~-1%" == "\" set "FolderToBackup=%FolderToBackup:~0,-1%"
rem Exit the subroutine if the folder path was root folder of a drive.
if "%FolderToBackup:~2%" == "" goto :EOF
rem Does the folder to backup not exist? This skips also files!
if not exist "%FolderToBackup%\" goto :EOF

for %%J in ("%FolderToBackup%") do set "FolderName=%%~nxJ" & set "FolderPath=%%~dpJ"

rem Get last modification date/time of the folder to backup
rem in region dependent format which is YYYY-MM-DD hh:mm.
for %%J in ("%FolderToBackup%") do set "FolderTimeStamp=%%~tJ"

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.
"C:\Program Files\WinRAR\WinRAR.exe" a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- "%FolderPath%%FolderTimeStamp%_%FolderName%.rar" "%FolderToBackup%"
goto :EOF

:ErrorArg
if defined FolderToBackup (echo %~f0 "%FolderToBackup%") else echo %~f0
echo/
echo Error: This batch file must be started with path of an existing folder
echo        or the name of a list file with one or more folder paths. It is
echo        not possible to use this batch file with root folder of a drive.
echo/
pause

:EndBatch
rem Restore the environment as set before usage of command SETLOCAL at top.
endlocal

Please read the rem arks for explanation of this batch file. 请阅读REM方舟此批处理文件的解释。

In Total Commander (short: TC) this batch file can be called with one or more folder paths by using only one item in toolbar. 在Total Commander(简称:TC)中,仅使用工具栏中的一项即可使用一个或多个文件夹路径调用此批处理文件。 Specify as Command the batch file with full path and %L as Parameters . 将具有完整路径的批处理文件指定为Command并将Parameters指定为%L

TC executes the batch file with the folder path passed as first argument on dragging & dropping a single folder on this item in toolbar. TC使用将文件夹路径作为第一个参数传递的批处理文件来执行拖放操作,该路径是在工具栏中将此项目拖放到单个文件夹上时。

Clicking on item in toolbar with a folder active in active pane or with one or more folders selected in active pane results in execution of the batch file with TC creating temporarily the list file with the full qualified folder names of either active folder or the selected folder(s), except there is nothing selected in active pane and active is .. . 单击工具栏上的项目,其中活动窗格中有一个活动文件夹或在活动窗格中已选择一个或多个文件夹,这会导致执行批处理文件,而TC会临时创建具有活动文件夹或所选文件夹的完整合格文件夹名称的列表文件(s),但在活动窗格中没有选择任何内容,并且活动是..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM