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

Author Topic: write batch pgm to read files & run executable  (Read 2836 times)

0 Members and 1 Guest are viewing this topic.

maryken12

  • Guest
write batch pgm to read files & run executable
« on: February 12, 2007, 02:11:58 PM »
Help --I am a complete beginner!   I have a bunch of files in a directory and I want to write a batch program which will read the files one by one and run an executable against each one-
example- directory Test has:
ABC.doc
DDD.doc    
EEE.doc
I want to run a valid program against each one of the files in directory Test and then put each file out to another directory called Directory Real without any user intervention from me...

How would I do this??
Much appreciated  :)
« Last Edit: February 12, 2007, 02:12:57 PM by maryken12 »

WillyW



    Specialist
  • Thanked: 29
  • Experience: Experienced
  • OS: Windows XP
Re: write batch pgm to read files & run executable
« Reply #1 on: February 12, 2007, 05:46:23 PM »
Quote
Help --I am a complete beginner!   I have a bunch of files in a directory and I want to write a batch program which will read the files one by one and run an executable against each one-
example- directory Test has:
ABC.doc
DDD.doc    
EEE.doc
I want to run a valid program against each one of the files in directory Test and then put each file out to another directory called Directory Real without any user intervention from me...

How would I do this??
Much appreciated  :)


Are you using MS-DOS, or a command prompt under WinXP, or...?

In the meantime,   you might like to check out:
http://www.computerhope.com/forhlp.htm

You'll be using the      for      command.
That is some good reading on it.


Your batch file might have something like this in it:
Code: [Select]
for %%1 in (*.*) do [executable name here]



.



maryken12

  • Guest
Re: write batch pgm to read files & run executable
« Reply #2 on: February 13, 2007, 05:32:03 AM »
Thanks for the response. I am using Win XP with the command Prompt.  I will read what you suggested...
I see your code line below-  I guess I am trying to understand how variables such as files in a directory would be processed....


WillyW



    Specialist
  • Thanked: 29
  • Experience: Experienced
  • OS: Windows XP
Re: write batch pgm to read files & run executable
« Reply #3 on: February 13, 2007, 08:15:14 AM »
Quote
Thanks for the response. I am using Win XP with the command Prompt.  I will read what you suggested...
I see your code line below-  I guess I am trying to understand how variables such as files in a directory would be processed....



One after another.

Read it as    For each entry in the set of "*.*",  run something.exe
where  *.*  means "any file name here"    and      something.exe
is your executable that you want to run.


Try
for %%1 in (*.*) do  echo %%1  
in a batch file.
It should print to screen a list of files in the directory.

Try
for %%1 in (*.bat) do echo %%1
and it should print a list of files, but only those files whose extension is    bat  

Try
for %%1 in (foo*.*) do  echo %%1
and it should print a list of files, but only those files whose names begin with     foo    

Getting a feel for it now?    :)

Of course, the command      echo          can be replaced with the executable of your choice,  or even another batch file to run.

Playing around with silly and simple examples is often a good way to get a grasp on what things do, before you try to implement it in a real -  and often more complicated -  job.

.



WillyW



    Specialist
  • Thanked: 29
  • Experience: Experienced
  • OS: Windows XP
Re: write batch pgm to read files & run executable
« Reply #4 on: February 13, 2007, 08:25:04 AM »
Quote
Help --I am a complete beginner!
- - -

Bookmark these:

http://www.computerhope.com/batch.htm
all the commands are not on this page.  There are other pages on this site.  
Good reading here, and links.


http://www.computerhope.com/msdos.htm

http://www.computerhope.com/overview.htm

http://www.vfrazee.com/ms-dos/6.22/help/
This one is interesting ... it is what we used to get when we
 typed         help         at the command line in good ol' dos 6.22   .
Note that each command listed is a hyperlink to more info, notes, and examples.
There may be slight differences!  as compared to the command prompt under WinXP.

Remember too:     at the command prompt,  type your command followed by   /?
as in       for  /?
or
             choice /?

and it will usually reply with some brief help.


I hope this helps.




.