execute a command on selected files
Moderators: Hacker, petermad, Stefan2, white
-
- Junior Member
- Posts: 8
- Joined: 2010-06-23, 19:22 UTC
execute a command on selected files
Hi,
is there a way to execute a command, probably from the command line, on selected files in a window? (Midnight Commander on the unix side has a way to do this, but don't know if Total Commander has a way.)
Thanks,
Russ
is there a way to execute a command, probably from the command line, on selected files in a window? (Midnight Commander on the unix side has a way to do this, but don't know if Total Commander has a way.)
Thanks,
Russ
- ghisler(Author)
- Site Admin
- Posts: 50811
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
You can create a button for that, with parameter %P%S (starts program once with all files as separate parameters) or with tool lst2multi from our addons page (starts tool once per selected file):
http://www.ghisler.com/tools.htm#other
http://www.ghisler.com/tools.htm#other
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
-
- Junior Member
- Posts: 8
- Joined: 2010-06-23, 19:22 UTC
That comes close.
I want to run a command that takes a single input and output file as parameters and run that command across all the selected files in the source directory and have the output sent to the target directory.
I have the parameters as %P%S %T%S, thinking that for each selected file in the source, i would be passing the target directory, with the filename, as the output.
This only seems to work if i've selected a single file.
Am i doing this right?
thanks,
Russ
I want to run a command that takes a single input and output file as parameters and run that command across all the selected files in the source directory and have the output sent to the target directory.
I have the parameters as %P%S %T%S, thinking that for each selected file in the source, i would be passing the target directory, with the filename, as the output.
This only seems to work if i've selected a single file.
Am i doing this right?
thanks,
Russ
- ghisler(Author)
- Site Admin
- Posts: 50811
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
No, %P%S %T%S would paste the x selected files (in source dir) with source path followed by the x selected files (in source dir too) with target path, which doesn't make much sense...
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
russurquhart1, if you want to execute some program with path to file in source panel and with path to file with same name but in target panel. So you can use following CMD file:
Place it anywhere and create buttonbar button:
E.g. if I have source path D:\ and target C:\ and files 1.txt, 2.txt, 3.txt selected and button parameter is fc.exe %F "%P" "%T", batch will execute following commands:
If it is not what you want you should describe what you want with details.
Code: Select all
@echo off
if -%4==- echo First parameter must be path to program to be executed, second one - filelist path, third and forth - source and target path. && pause && goto :EOF
for /F "usebackq delims=" %%f in (%2) do start /w "" %1 %3\"%%f" %4\"%%f"
cls
When you click a button, TC will generate list of selected files and pass to batch which will parse list and pass to program filename with source and with target path appended. Batch will wait for program exit before start it with next pair. If you want to start all instances simultaneously, remove /w parameter of start command.Command: path\to\this\batch
Parameters: "path\to\program\to\execute\for\each\pair" %F "%P" "%T"
E.g. if I have source path D:\ and target C:\ and files 1.txt, 2.txt, 3.txt selected and button parameter is fc.exe %F "%P" "%T", batch will execute following commands:
Code: Select all
start /w fc.exe D:\1.txt C:\1.txt
start /w fc.exe D:\2.txt C:\2.txt
start /w fc.exe D:\3.txt C:\3.txt
-
- Junior Member
- Posts: 8
- Joined: 2010-06-23, 19:22 UTC
That is what i want to do, and it is almost there but i think there is still a problem.
I am trying to run the epstool command. It takes, or i want to pass, two parameters to the command as well; the --copy and --bbox.
My command will be:
epstool --copy --bbox infile.eps outfile.eps
Your batch file seems to work except it looks like i am getting, for the file parameters:
c:\program files\epstool\bin""test.ps
and
c:\""test.ps
I seem to be getting an extra set of double quotes before the filename.
I changed the bat file, to add the parameters i needed as follows:
@echo off
if -%4==- echo First parameter must be path to program to be executed, second one - filelist path, third and forth - source and target path. && pause && goto :EOF
for /F "usebackq delims=" %%f in (%2) do start /w "" %1 " --copy --bbox " %3\"%%f" %4\"%%f"
cls
I didn't think this would cause the problem.
Thanks for your help.
Russ
I am trying to run the epstool command. It takes, or i want to pass, two parameters to the command as well; the --copy and --bbox.
My command will be:
epstool --copy --bbox infile.eps outfile.eps
Your batch file seems to work except it looks like i am getting, for the file parameters:
c:\program files\epstool\bin""test.ps
and
c:\""test.ps
I seem to be getting an extra set of double quotes before the filename.
I changed the bat file, to add the parameters i needed as follows:
@echo off
if -%4==- echo First parameter must be path to program to be executed, second one - filelist path, third and forth - source and target path. && pause && goto :EOF
for /F "usebackq delims=" %%f in (%2) do start /w "" %1 " --copy --bbox " %3\"%%f" %4\"%%f"
cls
I didn't think this would cause the problem.
Thanks for your help.
Russ
Actually you may execute epstool directly from batch:
And use just parameters: %F "%P" "%T"
Please note that quotes are removed from parameters during their processing, so parameter string "a b c ""d e f" is identical to string "a b c d e f" and parameter string "C:\Program Files"\"1.eps" is identical to string "C:\Program Files"\1.eps or string "C:\Program Files\1.eps" (strings in double quotes are concatenated and quotes are removed when parameter is being extracted). In your case filenames in filelist can contain spaces and source/target path can contain spaces - so they must be enclosed with pair of double quotes.
Code: Select all
@echo off
if -%3==- echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF
for /F "usebackq delims=" %%f in (%2) do "c:\program files\epstool\bin\epstool" --copy --bbox %2\"%%f" %3\"%%f"
cls
Please note that quotes are removed from parameters during their processing, so parameter string "a b c ""d e f" is identical to string "a b c d e f" and parameter string "C:\Program Files"\"1.eps" is identical to string "C:\Program Files"\1.eps or string "C:\Program Files\1.eps" (strings in double quotes are concatenated and quotes are removed when parameter is being extracted). In your case filenames in filelist can contain spaces and source/target path can contain spaces - so they must be enclosed with pair of double quotes.
Hello Russ
maybe you should take a look here:
Transformer Framework - Transform everything with TC!
http://ghisler.ch/board/viewtopic.php?t=23503
A powerful, but not complete finished plugin ...
Peter
maybe you should take a look here:
Transformer Framework - Transform everything with TC!
http://ghisler.ch/board/viewtopic.php?t=23503
A powerful, but not complete finished plugin ...
Peter
TC 10.xx / #266191
Win 10 x64
Win 10 x64
-
- Junior Member
- Posts: 8
- Joined: 2010-06-23, 19:22 UTC
Just add pause command:
Also you may turn debug mode on by removing @echo off line (in this case every command to be executed will be printed before).
Code: Select all
@echo off
if -%3==- echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF
for /F "usebackq delims=" %%f in (%2) do "c:\program files\epstool\bin\epstool" --copy --bbox %2\"%%f" %3\"%%f"
pause
cls
-
- Junior Member
- Posts: 8
- Joined: 2010-06-23, 19:22 UTC
Hi,
Sorry to report this is still not working. I am trying to run the command, on a few files selected in the epstools directory, i got the following:
c:\Program Files\epstool\bin>if -"c:\" == - echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF
c:\Program Files\epstool\bin>for /F "usebackq delims=" %f in ("c:\Program Files\epstool\bin\") do "c:\program files\epstool\bin\epstool.exe" --copy --bbox "c:\P
rogram Files\epstool\bin\"\"%f" "c:\"\"%f"
The system cannot find the file c:\Program Files\epstool\bin\.
c:\Program Files\epstool\bin>pause
Press any key to continue . . .
Any ideas?
Thanks,
Russ
Sorry to report this is still not working. I am trying to run the command, on a few files selected in the epstools directory, i got the following:
c:\Program Files\epstool\bin>if -"c:\" == - echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF
c:\Program Files\epstool\bin>for /F "usebackq delims=" %f in ("c:\Program Files\epstool\bin\") do "c:\program files\epstool\bin\epstool.exe" --copy --bbox "c:\P
rogram Files\epstool\bin\"\"%f" "c:\"\"%f"
The system cannot find the file c:\Program Files\epstool\bin\.
c:\Program Files\epstool\bin>pause
Press any key to continue . . .
Any ideas?
Thanks,
Russ
Sorry its my mistake (I didn't check it)... Of course, %1 (path to filelist) should be in brackets instead of %2 (source path):
Button parameters:
Here %1 in file will be replaced with path to filelist, %2 - with source path, %3 - with target path.
Code: Select all
@echo off
if -%3==- echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF
for /F "usebackq delims=" %%f in (%1) do "c:\program files\epstool\bin\epstool" --copy --bbox %2\"%%f" %3\"%%f"
pause
cls
Code: Select all
%F "%P" "%T"
-
- Junior Member
- Posts: 8
- Joined: 2010-06-23, 19:22 UTC
1. Do you try to process files from "c:\Program Files\epstool\bin" folder? (if yes, all ok)
2. It is strange that path doesn't contain slash since in batch it is specified explicitly:
If it will success, epstool understands concatenation of quoted strings.
2. It is strange that path doesn't contain slash since in batch it is specified explicitly:
3. You may try to pass path with extra quotes to ensure epstool correctly processes them - just execute any command manually from Windows command line, e.g.:Failed to open "c:\Program Files\epstool\bin""test2.eps".
Code: Select all
"c:\program files\epstool\bin\epstool.exe" --copy --bbox "c:\Program Files\epstool\bin"\"test2.eps" "c:\"\"test2.eps"