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











up vote
1
down vote

favorite












Reference: How to create a RAR archive with date of the archived folder in archive file name?



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%WinRARWinRAR.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.



I configured the batch file to be a button on the button bar of TC with the button setting Parameters: %s. When the active item is a folder like d:docaatemp 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.



For more than one folder I want to do as above.



So I made another batch file with the button setting 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.



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!WinRARWinRAR.exe" a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- !FolderTimeStamp!_!FolderToBackup!.rar !FolderToBackup!
c:Program FilesWinRARWinRAR.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.



The command line with WinRAR.exe cannot work with the list file as I want it.










share|improve this question




























    up vote
    1
    down vote

    favorite












    Reference: How to create a RAR archive with date of the archived folder in archive file name?



    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%WinRARWinRAR.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.



    I configured the batch file to be a button on the button bar of TC with the button setting Parameters: %s. When the active item is a folder like d:docaatemp 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.



    For more than one folder I want to do as above.



    So I made another batch file with the button setting 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.



    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!WinRARWinRAR.exe" a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- !FolderTimeStamp!_!FolderToBackup!.rar !FolderToBackup!
    c:Program FilesWinRARWinRAR.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.



    The command line with WinRAR.exe cannot work with the list file as I want it.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Reference: How to create a RAR archive with date of the archived folder in archive file name?



      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%WinRARWinRAR.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.



      I configured the batch file to be a button on the button bar of TC with the button setting Parameters: %s. When the active item is a folder like d:docaatemp 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.



      For more than one folder I want to do as above.



      So I made another batch file with the button setting 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.



      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!WinRARWinRAR.exe" a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- !FolderTimeStamp!_!FolderToBackup!.rar !FolderToBackup!
      c:Program FilesWinRARWinRAR.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.



      The command line with WinRAR.exe cannot work with the list file as I want it.










      share|improve this question















      Reference: How to create a RAR archive with date of the archived folder in archive file name?



      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%WinRARWinRAR.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.



      I configured the batch file to be a button on the button bar of TC with the button setting Parameters: %s. When the active item is a folder like d:docaatemp 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.



      For more than one folder I want to do as above.



      So I made another batch file with the button setting 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.



      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!WinRARWinRAR.exe" a -ac -cfg- -dh -ep1 -ibck -m4 -oh -ol -os -ow -r -ts -y -- !FolderTimeStamp!_!FolderToBackup!.rar !FolderToBackup!
      c:Program FilesWinRARWinRAR.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.



      The command line with WinRAR.exe cannot work with the list file as I want it.







      batch-file buttonbar total-commander






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 16:22









      Mofi

      27.3k83676




      27.3k83676










      asked Nov 9 at 12:56









      Tangent Lin

      204




      204
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          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.



          @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 FilesWinRARWinRAR.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 remarks for explanation of this batch file.



          In Total Commander (short: TC) this batch file can be called with one or more folder paths by using only one item in toolbar. Specify as Command the batch file with full path and %L as Parameters.



          TC executes the batch file with the folder path passed as first argument on dragging & dropping a single folder on this item in toolbar.



          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 ...






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226130%2fhow-to-integrate-batch-file-with-total-commander-gui-selected-files-directorie%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            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.



            @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 FilesWinRARWinRAR.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 remarks for explanation of this batch file.



            In Total Commander (short: TC) this batch file can be called with one or more folder paths by using only one item in toolbar. Specify as Command the batch file with full path and %L as Parameters.



            TC executes the batch file with the folder path passed as first argument on dragging & dropping a single folder on this item in toolbar.



            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 ...






            share|improve this answer



























              up vote
              0
              down vote



              accepted










              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.



              @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 FilesWinRARWinRAR.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 remarks for explanation of this batch file.



              In Total Commander (short: TC) this batch file can be called with one or more folder paths by using only one item in toolbar. Specify as Command the batch file with full path and %L as Parameters.



              TC executes the batch file with the folder path passed as first argument on dragging & dropping a single folder on this item in toolbar.



              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 ...






              share|improve this answer

























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                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.



                @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 FilesWinRARWinRAR.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 remarks for explanation of this batch file.



                In Total Commander (short: TC) this batch file can be called with one or more folder paths by using only one item in toolbar. Specify as Command the batch file with full path and %L as Parameters.



                TC executes the batch file with the folder path passed as first argument on dragging & dropping a single folder on this item in toolbar.



                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 ...






                share|improve this answer














                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.



                @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 FilesWinRARWinRAR.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 remarks for explanation of this batch file.



                In Total Commander (short: TC) this batch file can be called with one or more folder paths by using only one item in toolbar. Specify as Command the batch file with full path and %L as Parameters.



                TC executes the batch file with the folder path passed as first argument on dragging & dropping a single folder on this item in toolbar.



                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 ...







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 9 at 16:42

























                answered Nov 9 at 15:41









                Mofi

                27.3k83676




                27.3k83676






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226130%2fhow-to-integrate-batch-file-with-total-commander-gui-selected-files-directorie%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Hercules Kyvelos

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud