Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Going through all files  (Read 3990 times)

0 Members and 1 Guest are viewing this topic.

Zipper

  • Guest
Going through all files
« on: September 02, 2004, 04:17:52 PM »
I'm sure this is easy, but just don't seem to be able to get it. I'm trying to create a batch program that I want to go through all files in a directory and then take each file and run a program with that file as the paramater for the program. IE there is a directory call Foo, and in the directory there is Bar1.txt, bar2.txt (etc....). I want this batch file to go through the current directory and grab all files and supply them to another program. i.e.

Start "C:\Program Files\7-zip\7z.exe" filename

Of course the bat file would supply the filename as it goes through the directory. I can do everything other than going through a directory grabbing the file names. Sorry if this is easy, but I can't seem to figure it out. Any help would be greatly appreciated. Thanks.

-Zipper

remigrath

  • Guest
Re: Going through all files
« Reply #1 on: September 05, 2004, 04:55:16 PM »
I know this isn't exactly what you wanted to do, but...

How about doing something like:

dir "C:/directory" /b > directory.txt

That would create a list of filenames in the given directory called "directory.txt" You could have your program run through that file and then do what you want it to do with each file.

If you wanted to do this from a program you could just pass that command above into the C function system().

Anyway, not great description, but I hope that helps.

remigrath

  • Guest
Re: Going through all files
« Reply #2 on: September 05, 2004, 04:58:17 PM »
I just realized you wanted to do this only using batch. I don't know if it's possible.

If I were you I'd just go ahead and make a C or a C++ program that you could run by doing "program.exe target_file_name" where the target_file_name is the name of the file to pipe stuff into and then do what I said in my last post.

Argh, I'm confusing myself, I'll stop.

If you want me to clarify something I said, let me know.

Zipper

  • Guest
Re: Going through all files
« Reply #3 on: September 06, 2004, 12:59:16 AM »
I agree with you I can't do it through batch. I decided to just go ahead and do it through Perl. Took like 20 mins, and that was just becuase I haven't dealt with Perl in forever. Thanks again.

-Zipper