If only I knew how to write Batch scripts...

DMZ

DMZ

Associate
Joined
30 Jul 2011
Posts
133
Hi all

I have a little command line app that takes a file, processes it and outputs it as a new file. The syntax is: <input file> <output file> <operation> <arguments>.

What I want to do is have it run on a folder which contains hundreds of files. I thought a Batch script might be able to do this. I've used one before where I dragged a folder onto the script and it processed all the files in the folder and saved them. I'd be happy if the originals were overwritten.

Would anyone be able to help me make a Batch file like this? I tried a few things from Google but they didn't work.

Thanks :)
 
Last edited:
dir /b >a.txt.. past the contents of the file into excel, now jsut build the command in excel

eg

colA = the text commandname.exe
colB = the text file name you pasted in
colc = the formula colB & "new"
cold = <operation> <arguments>
cole = colA&colB&colCandcolD

dont forget to put spaces at the end of values that need spaces (eg colA)

fill the statif values and formulas down, the jsut copy and past the result from colE into a dos window..

possibly sounds more complicated that it is...
 
for %i in (*.txt) do echo %i

Will iterate through a bunch of files doing whatever command is in the place of echo in this instance %i will be the filename.

replace %i with %%i if in a batch file, should be able to work it out from there.

EDIT: Using this method will require 2 batch files due to some oddities in DOS:

list.bat said:
@echo off
for %%i in (*.txt) do call do.bat %%i

do.bat said:
@echo off
set out=%1
set out=%out:~0,-3%jpg
echo old file %1 new file %out%

replace the echo command with the command you want to use and jpg with the new extension (this assumes all files are nicely named "blahblah.ext") its possible to do other stuff with string manipulation for the output name rather than just change the extension. %1 is the input filename variable and %out the output filename.
 
Last edited:
Back
Top Bottom