There’s a command line program I use that does operations on files. However it does it one file at a time. For example, if I have 3 files named 1.txt, 2.txt and 3.txt I have to type:
C:>xyz 1.txt
C:>xyz 2.txt
C:>xyz 3.txt
Imagine now that the files are 50+ and their names are random, ie do not have a predefined naming scheme.
I want to make a simple bat file that sends the output of dir /b command to xyz so I do not have to type each filename by hand.
pipe is to direct out put to another program that will act on it - you could further tht to a txt file but often its for narrowing down the screen display
netstat -an | find “listen”
will send the output of xyz to a new text file called 1.txt
c:>xyz >> 1.txt will append the output of xys to the 1.txt file - if it doesnt exist, it will be created.
If one of the things that xyz takes is a parm called 1.txt (a file to parse) -
c:>xyz 1.txt > output1.txt will do the same thing.
All this assumes, of course - that the ‘xyz’ puts data back out to the cmd window that you would see when you run it - if it does not, there is simply nothing to ‘redirect’ .
From what I’m understanding in the OP, he’s not wanting to redirect the output of xyz. He’s wanting to redirect the output of the dir command to call xyz with each filename it encounters.
Assuming this, it would be something like:
dir [param] would result in:
1.txt
2.txt
3.txt
He would then want xyz to be called with each filename as a parameter.
As I stated, as long as the .txt files are all in the same folder, I can write an app to let you do this.
You’d just need to setup the path to xyz and the path to the files you want as parameters when first running the app.
Also, any further files added to the data folder would automatically be added for you, too.
I would simply rethink the problem and a complicated program should not be needed -
new bat file -
dir > directory.txt
then read in directory.txt and loop thru each line and call xyz.
dir /b | xyz would address #1. “/b” eliminates all the extra information.
#2: If executable ‘xyz’ could handle a list of filenames we wouldn’t be here in the first place.
The question has been answered a couple miles back with the for-in constructions. There is no need for any additional half-baked ideas… the answer is right up there. I even tried to come up with a pure text-type solution and without "sed’ or similar I couldn’t do it.
Just for the record, “>”, “>>”, and “|” only redirect stdout, not stderr. That’s how you see the error message on the console if you try to do something like so: