I have since found that TC does not do proper quoting of passed parameters (arguments) when they don't contain spaces. It is especially bad when a filename contains an ampersand "&".
NOTE: Since cmd.exe is launched, the path is known, thus %P%S is not needed, only %S.
Code: Select all
::
::MultiFileOpen.cmd v2.01
::
::Overview: Launched via a Total Commander Button:
:: Command: cmd /c MultiFileOpen.cmd "C:\Path\to\Your\Program.exe"
:: Parameters: %S
::Currently: Launched via AutoHotkey, from TC Button:
:: Command: %AHK%\TC_QuoteArgs.ahk "MultiFileOpen2.cmd" "%AppEditText%\NotePad2\notepad2.exe"
:: Parameters: %S
::
::Purpose(1)* Dont pass %S Args to Program when Cursor is on [..] or Folder.
::
::Purpose(2) When MultipleFiles are selected, Pass QUOTED "%S" arguments 1 at a time.
::
::Purpose(3) If used with NotePad2,in your NotePad2.ini, underneath [Settings2]
:: add: DefaultDirectory=%EditorDefaultDIR%
::
:: If used with TedNotePad, in your TedNPad.ini, underneath [Setts]
:: add: DefPath=%EditorDefaultDIR%
::
::Purpose(4) If cursor is on a Folder, Start an empty instance of Program from that DIR.
::
::
:: *Prevents the annoyance of things like NotePad2 showing the
:: OpenFileDialog instead of just Starting (with no file).
::
:: History:
:: Previous version 1.xx was launched via a TotalCommander Button, but I found that
:: TC does not properly quote files. This is highly problematic when characters such
:: as &!% are encountered in file names that don't have spaces. The ampersand, especially,
:: completely breaks most scripts when it is encountered and NOT quoted.
::
:: Thus I have had to use AutoHotKey to properly quote the files before passing back
:: into the MultiFileOpen.cmd script.
::
::
:: NOTES:
:: %AHK% and %AppEditText% are both SET in the RunTC.cmd I use to launch Total Commander.
:: --> SET AHKDir=%ProgramFiles%\AutoHotKey
:: --> SET AHK="%AHKDir%\AutoHotkey.exe" "%AHKDir%\Scripts"
::
:: AppEditText has a convoluted SET, as it's path contains a non-standard character.
:: and CMD.exe doesn't like those characters in a batch file. Nor have I been able to
:: get CMD.exe to launch/run a UTF or unicode .cmd file.
::
::
Code: Select all
@ECHO OFF
CLS
SET xProgram="%~1"
IF "%~2"=="" CALL:_OPEN_FROM_FOLDER "%CD%"&GOTO:END
:_MAIN_OLOOP
SHIFT
SET isDir=-%~a1-
SET isDir=%isDir:~1,1%
IF -%isDir%-==-d- CALL:_OPEN_FROM_FOLDER "%~1"&GOTO:_NEXT
START "" %xProgram% "%~1"
:_NEXT
IF "%~2" NEQ "" GOTO:_MAIN_OLOOP
GOTO:END
:_OPEN_FROM_FOLDER
PUSHD "%~1"
SET "EditorDefaultDIR=%CD%"
START "" %xProgram%
POPD
GOTO:EOF
:END
SET xProgram=
SET isDir=
Code: Select all
;;
;; TC_QuoteArgs.ahk
;;
#SingleInstance, Force
#NoEnv
SetBatchLInes, -1
fileList := "", fileName := ""
Loop, %0%
{
if( A_Index < 3 )
continue
fileName := %A_Index%
fileList = %fileList% `"%fileName%`"
}
Run, %comspec% /s /c ""%1%" "%2%" %fileList%",, Min
return
OLD Version 1.85:Download MultiFileOpen v1.852.01: Rewrite. Cleaner. Optional AHK preLauncher to fix Total Commander's broken argument quoting mechanism.
1.85: *Fixed broken variable expansion inside IF ( )
....... Fixed Notepad2.exe comparison by uppercasing filename.
(*) Knew variable expansion did not occur within FOR loops when ENABLEDELAYEDEXPANSION was off , but was unaware that also occured within any brace(d) code.
1.70: Automatic detection of NotePad2.exe; change to SETLOCAL
1.50: Apparently FART.exe is not completely unicode compliant, though
....... It is more functional than gsar. Rewrite of NotePad2's DefaultDir.
1.11: FIX: Quirk with :~0,1 path expansion, caused by v1.05.
1.10: FIX: Moved "::" Label comments outside of ( ) code blocks.
......: as noted here, IRT: "The system cannot find the drive specified."
Didn't prevent functionality, but did cause a system <beep>
1.05: Removed ENABLEDELAYEDEXPANSION, and any conflict with Files named with "!".