How to batch automate a command line tool on selected files

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Spoor
Junior Member
Junior Member
Posts: 3
Joined: 2020-10-19, 16:10 UTC

How to batch automate a command line tool on selected files

Post by *Spoor »

I've the following case where I select files to be processed by a command line tool with options.
It's usually always the following command line: "tool.exe [options set] [path]original_file.txt [options set] [path]result_file.txt"

I've seen on the wiki that TC supports scripting but frankly I don't quite get it and couldn't get it to work.
I would appreciate if someone can give a simple script I can just plug-in.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: How to batch automate a command line tool on selected files

Post by *MVV »

E.g. you can use such BAT file:

Code: Select all

@echo off
if -%1==- echo Parameters: %%WL "%%T" & pause & goto :EOF
for /f "usebackq delims=" %%f in (`type "%~1"`) do echo tool.exe [options set] "%%~f" [options set] "%~2\%%~nxf"
pause
It will apply command for every selected file and pass path to the file and path to it in an opposite panel, with other parameters that are written in third line. If you remove echo word from third line, it will execute command instead of just printing it, also you can remove pause command.
User avatar
nsp
Power Member
Power Member
Posts: 1804
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: How to batch automate a command line tool on selected files

Post by *nsp »

If you want to create ans run a batch file from selected files, you can use TCBL using %L to pass all the selected files.
If the script is simple you can use a simple command line as a user command or button in TC.
if you need something more complicated or keep it for multiple uses, you can define in tcbl.ini a command section.
-- Limitations:
  • only works with real files
  • only use %L or %F to get list of file (no support to Utf-8/Unicode %UL,%WL) and be aware of TC bug Max len of line is 260 Byte.
  • need small learning time (I will be pleased to help.)
You can also build dedicated batch script, cmd , powershell, ..... using %L and looping over each entry. To parse or extract in cmd batch, you can use %~ notation (Parameter extension) this also works for ...
Post Reply