Executing a .bat file for each file in the search result.

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
gerthmar
New Member
New Member
Posts: 1
Joined: 2013-05-16, 09:59 UTC

Executing a .bat file for each file in the search result.

Post by *gerthmar »

I have a directory tree with different files in it, and i would like to execute a .bat file for each of these file that is ending with ".sct", no matter where in the directory tree the file is.

I already tried to do this selecting all files in the search results and using the "Start" menu, but when i use the "%P%S" argument in the parameter field, TC only passes the path of one single file to the .bat file, instead of all selected files.

Am I missing something, or could this be a bug?

Cheers!
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6507
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Executing a .bat file for each file in the search result

Post by *Horst.Epp »

gerthmar wrote:I have a directory tree with different files in it, and i would like to execute a .bat file for each of these file that is ending with ".sct", no matter where in the directory tree the file is.

I already tried to do this selecting all files in the search results and using the "Start" menu, but when i use the "%P%S" argument in the parameter field, TC only passes the path of one single file to the .bat file, instead of all selected files.

Am I missing something, or could this be a bug?

Cheers!
Check your batch file.
This works perfectly and there is no bug in this function of TC
User avatar
nsp
Power Member
Power Member
Posts: 1813
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Executing a .bat file for each file in the search result

Post by *nsp »

gerthmar wrote:I have a directory tree with different files in it, and i would like to execute a .bat file for each of these file that is ending with ".sct", no matter where in the directory tree the file is.

I already tried to do this selecting all files in the search results and using the "Start" menu, but when i use the "%P%S" argument in the parameter field, TC only passes the path of one single file to the .bat file, instead of all selected files.

Am I missing something, or could this be a bug?

Cheers!
if you use %P%S you will get a long list of all selected file on a single line. The bat file you specify will be called only once.
If you want to call a bat file multiple time having the selected file as parameter passed one by one, you need to use an intermediate batch, tools or modify your current bat to accept more than one parameter.
Another solution is to use TCBL or other wrapper.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Code: Select all

@echo off
rem Processing of %P%S
:loop_next
if -%1==- goto loop_end
echo Do something with "%~1"
shift
goto loop_next
:loop_end
pause

Code: Select all

@echo off
rem Processing of %L or %WL
for /f "usebackq delims=" %%s in (`type %1`) do echo Do something with "%%s"
pause
BTW if you're using %P%S, you should note that command line length is limited so it won't work with large selections.
Post Reply