Two questions here:
I'm exploring the functionality of passing filenames as arguments to programs and scripts (Command:) in the Parameters: field of a custom configured button.
I wrote a small batch script to help me observe how different things work:
Code: Select all
@echo off
REM Loop through the parameters
for %%i in (%*) do (
echo %%i
)
timeout /t 50
I then created a button with
d:\script.bat in the the Command: textfield and
%P%S in the Parameters: textfield. I then select/mark a couple of files in the pane and click the button. Script opens a CMD window and prints out their paths and filenames, for example:
Code: Select all
"d:\Downloads\File One.txt"
"d:\Downloads\File Two.txt"
"d:\Downloads\File Three.txt"
However, if I happen to also select/mark a file named
FileFour.txt (notice no space), then the script won't run at all. This is probably because TC doesn't put double quotes around this one since it sees there is no space in the path & filename, and so it breaks for some reason. If I introduce a space by renaming the
Downloads folder to
Down loads or if I simply put a space in the filename, then it will work again. The solution is to put
"%P%S" in double quotes in the Parameters: textfield, even though the help pages say not to:
Code: Select all
%P%S
insert the names of all selected files into the command line, with full path. Names containing spaces will be surrounded by double quotes. Do NOT put quotes around %P%S yourself!
I guess it only works without quotes if passing those parameters to a program (some_program.exe) but with a batch script, you apparently need to use them. Or is there something I can change in the script itself so that it will correctly receive the agruments and run even if I don't put %P%S in double quotes?
Second question:
%P%S passes the names of all selected files into the command line
%N passes the filename under the cursor into the command line
Is there a way to pass the file name only if it is MARKED (right-click with the mouse to make it red) and NOT if it is only selected (under the cursor)? I would like to avoid any accidents if I mistakenly click on the button which would cause at least one file/folder to be passed as an argument and get "worked on".