execute a command on selected files

English support forum

Moderators: Hacker, petermad, Stefan2, white

russurquhart1
Junior Member
Junior Member
Posts: 8
Joined: 2010-06-23, 19:22 UTC

execute a command on selected files

Post by *russurquhart1 »

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
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50811
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

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
Author of Total Commander
https://www.ghisler.com
russurquhart1
Junior Member
Junior Member
Posts: 8
Joined: 2010-06-23, 19:22 UTC

Post by *russurquhart1 »

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
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50811
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

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
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

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:

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
Place it anywhere and create buttonbar button:
Command: path\to\this\batch
Parameters: "path\to\program\to\execute\for\each\pair" %F "%P" "%T"
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.

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
If it is not what you want you should describe what you want with details.
russurquhart1
Junior Member
Junior Member
Posts: 8
Joined: 2010-06-23, 19:22 UTC

Post by *russurquhart1 »

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
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Actually you may execute epstool directly from batch:

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
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.
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

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
TC 10.xx / #266191
Win 10 x64
russurquhart1
Junior Member
Junior Member
Posts: 8
Joined: 2010-06-23, 19:22 UTC

Post by *russurquhart1 »

Hate to be a stickler, but this still isn't working for me.

Is there a way to keep the window from closing, that shows the commands being executed, so i can kind of tell what's going on?

Thanks,


Russ
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Just add pause command:

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
Also you may turn debug mode on by removing @echo off line (in this case every command to be executed will be printed before).
russurquhart1
Junior Member
Junior Member
Posts: 8
Joined: 2010-06-23, 19:22 UTC

Post by *russurquhart1 »

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
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Sorry its my mistake (I didn't check it)... Of course, %1 (path to filelist) should be in brackets instead of %2 (source 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
Button parameters:

Code: Select all

%F "%P" "%T"
Here %1 in file will be replaced with path to filelist, %2 - with source path, %3 - with target path.
User avatar
ehab
Senior Member
Senior Member
Posts: 271
Joined: 2007-10-29, 07:41 UTC
Location: Libya

Post by *ehab »

MVV is the script master : )

thanks for adding last update
#181344 Personal licence
russurquhart1
Junior Member
Junior Member
Posts: 8
Joined: 2010-06-23, 19:22 UTC

Post by *russurquhart1 »

Almost there!

Here's the latest:

Failed to open "c:\Program Files\epstool\bin""test2.eps".
Run "epstool --help" for more details.
Failed to open "c:\Program Files\epstool\bin""test.eps".
Run "epstool --help" for more details.
Press any key to continue . . .

Any ideas?

Thanks again!

Russ
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

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:
Failed to open "c:\Program Files\epstool\bin""test2.eps".
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.:

Code: Select all

"c:\program files\epstool\bin\epstool.exe" --copy --bbox "c:\Program Files\epstool\bin"\"test2.eps" "c:\"\"test2.eps"
If it will success, epstool understands concatenation of quoted strings.
Post Reply