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

Author Topic: For loop for running a batch file  (Read 3513 times)

0 Members and 1 Guest are viewing this topic.

Jon-Paul

  • Guest
For loop for running a batch file
« on: November 24, 2004, 03:03:59 AM »
Hiya. I'm running a script to automatically create directories. The script so far looks like this:


***************************************
mkdir companies
mkdir candidates
cd companies

cat ../companies.cfg | perl -e "while (<>) {chomp;mkdir($_)}"

cd..
cd candidates

cat ../candidates.cfg | perl -e "while (<>) {chomp;mkdir($_)}"

cd..


*****************************

The candidates.cfg and companies.cfg simply contain the directory names to be created in each of those to sub directories.

Anyway, this script needs to be run so the same directory structure appears in all the parent folders. For example

1/companies/directory 1
1/companies/directory 2
1/candidates/directory 1
1/candidates/directory 2

2/companies/directory 1
2/companies/directory 2
2/candidates/directory 1
2/candidates/directory 2

and so forth.

The parent directories (i.e. 1, 2, etc) have already been created. There are around 5000 of them.

What I need to know is how to autotmatically change to the different directories, run the script I have so far, then cd.. back to the parent and move onto the next directory.

Any ideas how?

Jon

MalikTous

  • Guest
Re: For loop for running a batch file
« Reply #1 on: November 24, 2004, 01:57:29 PM »
You're going to have fun using a for-in-do loop with either a generic list of directories or the output of a dir command as its parameters. If you have previously made some of the directories, change all

MD target

commands to

if not exist target\nul: md target

to prevent errors when creating directories.