Can I make a button to run the cmd for all selected files?

English support forum

Moderators: white, Hacker, petermad, Stefan2

avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Can I make a button to run the cmd for all selected files?

Post by *avada »

Hi!

What I want is to run the command N times for all selected files. Unlike %P%S, which only appends all of them.

(Some programs don't understand multiple input files)
Windows 10
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Sure. If your program supports a list file, you can make a button that calls your program directly and passes the list via %L, %WL or %UL respectively.

If it doesn't support file lists directly, you can still use a CMD for-loop to process all files. Something like this:

Code: Select all

@echo off

if "%~1"=="" goto :EOF

for %%L IN (%~1) DO (
    call D:\rive\and\path\to\your\program\here.exe "%%~L"
)
But make sure it's a CMD (console) program because if it isn't, the code above will start an instance for each file simultaneously.

Also note that things like this have been discussed in the past, so you can find other solutions in the forum.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

Dalai wrote:Sure. If your program supports a list file, you can make a button that calls your program directly and passes the list via %L, %WL or %UL respectively.

If it doesn't support file lists directly, you can still use a CMD for-loop to process all files. Something like this:

Code: Select all

@echo off

if "%~1"=="" goto :EOF

for %%L IN (%~1) DO (
    call D:\rive\and\path\to\your\program\here.exe "%%~L"
)
But make sure it's a CMD (console) program because if it isn't, the code above will start an instance for each file simultaneously.

Also note that things like this have been discussed in the past, so you can find other solutions in the forum.

Regards
Dalai
Thanks!

Though it's a nasty workaround. Which I assume you need to keep as separate batch file and can't be tinkered into the button.
Windows 10
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Workaround? Well, if you want to call it that. Which way would you go instead when some program doesn't process a list file by itself, and takes only one argument? It's a simple mechanism to use some kind of script, be it CMD, VBS, PowerShell, AutoIt, AutoHotkey or something else.

Maybe MakeBat is a better way? I don't know how this works, but I'm quite sure there's some info on the forum already.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

Dalai wrote:Workaround? Well, if you want to call it that. Which way would you go instead when some program doesn't process a list file by itself, and takes only one argument? It's a simple mechanism to use some kind of script, be it CMD, VBS, PowerShell, AutoIt, AutoHotkey or something else.

Maybe MakeBat is a better way? I don't know how this works, but I'm quite sure there's some info on the forum already.

Regards
Dalai
Well, I was hoping TC had another special parameter of which I was unaware of. And I could just %P%X or such. :)
Windows 10
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

I don't think that it's a file manager's job, at least not one without advanced scripting/macro capabilities, to launch a program for every selected file. And I also don't think it's necessary because there are plenty of options available to do such things - the most important ones mentioned above. It were a different story if TC had more dedicated scripting features, but that would TC make more complex, which would lead to even more bugs.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
nsp
Power Member
Power Member
Posts: 1803
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Can I make a button to run the cmd for all selected file

Post by *nsp »

avada wrote:Hi!

What I want is to run the command N times for all selected files. Unlike %P%S, which only appends all of them.

(Some programs don't understand multiple input files)
You can try TCBL tool, it is designed for this purpose. As TC do not have any script language nor any switch to run for each selected file.

Or build any intermediate powershel/scriptl launcher using the generated list File.

You will have some limitation if not working on standard file.
User avatar
petermad
Power Member
Power Member
Posts: 14740
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

2avada
Which I assume you need to keep as separate batch file and can't be tinkered into the button.
Here are two buttons for you with notepad as the command (replace with your program) - the first one opens all selceted files in notepad at the same time, the second button opens them one after another.

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if exist %S1\* ((echo DO NOT MARK DIRECTORIES!) && (echo.) && pause) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WF`) do start %%windir%%\notepad.exe "%%n"
wcmicons.dll,28
Open all selected files in notepad at the same time

1
-1

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if exist %S1\* ((echo DO NOT MARK DIRECTORIES!) && (echo.) && pause) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WF`) do call %%windir%%\notepad.exe "%%n"
wcmicons.dll,28
Open all selected files in notepad one after another

1
-1
To make the buttons:
1. Mark the green text above (including TOTALCMD#BAR#DATA in the first line and -1 in the last line).
2. Copy it to the ClipBoard (Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
The chcp 65001 && %%COMSPEC%% /C part is for supporting Unicode in the filenames - remove it if you are using Windows XP (some still do)
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

@nsp, @petermad

Thanks for the tips guys. I'll check them out.
Windows 10
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

petermad wrote:2avada
Which I assume you need to keep as separate batch file and can't be tinkered into the button.
Here are two buttons for you with notepad as the command (replace with your program) - the first one opens all selceted files in notepad at the same time, the second button opens them one after another.

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if exist %S1\* ((echo DO NOT MARK DIRECTORIES!) && (echo.) && pause) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WF`) do start %%windir%%\notepad.exe "%%n"
wcmicons.dll,28
Open all selected files in notepad at the same time

1
-1

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if exist %S1\* ((echo DO NOT MARK DIRECTORIES!) && (echo.) && pause) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WF`) do call %%windir%%\notepad.exe "%%n"
wcmicons.dll,28
Open all selected files in notepad one after another

1
-1
To make the buttons:
1. Mark the green text above (including TOTALCMD#BAR#DATA in the first line and -1 in the last line).
2. Copy it to the ClipBoard (Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
The chcp 65001 && %%COMSPEC%% /C part is for supporting Unicode in the filenames - remove it if you are using Windows XP (some still do)
Hmmm...
I can't seem to get this to work. Something with the path for the program I test it with. I replaced

Code: Select all

%%windir%%\notepad.exe
with

Code: Select all

"E:\alkalmazások - telepítők\Bittorrent\bencode\BEncode Editor.exe"
, but it wouldn't work.
Windows 10
User avatar
petermad
Power Member
Power Member
Posts: 14740
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

2avada
Try and put your program in a folder that does not use accented characters like á, í and ő and see if that helps...
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

petermad wrote:2avada
Try and put your program in a folder that does not use accented characters like á, í and ő and see if that helps...
Nope. They're opened with the associated application.
Windows 10
User avatar
petermad
Power Member
Power Member
Posts: 14740
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

Then try and set an environment variable for the program, like:
editor=E:\alkalmazások - telepítők\Bittorrent\bencode\BEncode Editor.exe

You can run SystemPropertiesAdvanced.exe to do that. Remembert to restart TC after that, so it can now the variable.

Example:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if exist %S1\* ((echo DO NOT MARK DIRECTORIES!) && (echo.) && pause) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WF`) do start "%%editor%%" "%%n"
wcmicons.dll,28
Open all selected files in notepad at the same time

1
-1
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
isidro
Junior Member
Junior Member
Posts: 96
Joined: 2006-03-21, 04:39 UTC
Location: argentina

Post by *isidro »

if there are spaces on either path or filename you will need to enclose all in ""
You may try first putting and renaming editor in a simpler way (with no spaces/strange chars on name or path) (ie: C:\UT\myeditor.exe)
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

isidro wrote:if there are spaces on either path or filename you will need to enclose all in ""
You may try first putting and renaming editor in a simpler way (with no spaces/strange chars on name or path) (ie: C:\UT\myeditor.exe)
I know but quotes don't help. And renaming/moving files is not viable, even though it works that way.
Windows 10
Post Reply