Computing.Net > Forums > Programming > Nested loop in batch file help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Nested loop in batch file help

Reply to Message Icon

Name: Smedley
Date: June 13, 2009 at 20:13:07 Pacific
OS: Windows XP PRO
CPU/Ram: P4 2.8 $GB
Subcategory: Batch
Comment:

I am testing relative performance and configuration of Hard Drives in different PC and through different network environments.

To do this I am wanting to create some known constants of my own, as well as some learning along the way.

As a part of this I am trying to make a nested loop in a Batch CMD file but without success.

Can you please advise me as to what I am missing?

I am trying to create a directory with multiple sub-directories, each of these sub-directories containing multiple small files. The sub-directories and file names can just uniquely numbered.

This will give me a large chunk of small files to handle and test with. Later I will do the same creating larger size files and will then be able to create a more realistic test.

So far I have three lines that work individually at least in part but I cannot get then to work together.

Here is what I have so far:

MD ABC
CD ABC
Create a directory and make it current.

FOR /L %%f in (1,1,1000) do md %%f

This line will create the sub-directories as intended

FOR /L %%g in (1,1,1000) do echo abc > %%g.abc

This line will create the 1000 files as intended but only in the root directory, it does not recurse through all of the sub-directories to continue making the files in each of them.

FOR /R %%h in (1,1,1000) do echo cba > %%h.cba

Using the /R instead of /L I am able to get the CMD file to recurse through but it only created two files in each directory. one is named 1.cba and the second is 100.cba

How do I wrap the recursing ability of the third line around the working function in line two?

Alan Smedley



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: June 13, 2009 at 22:58:42 Pacific
Reply:

I do not know what your performance expectations are. But I
had made a similar program using BASIC to test the creation
of CD-ROM from hard disk data files of relatively small files
with a directory structure 8 levels deep and file and directory
size of just exceeding one cluster size to maximize slack
space. In a partial trial I found that the time became greatly
dependent on the depth of the path. Copying is extremely
slow when the path is long. About 2 hours to create 1
directory at root plus sub-dirs 8 levels down plus files at the
deepest level.


0

Response Number 2
Name: Smedley
Date: June 13, 2009 at 23:17:08 Pacific
Reply:

A part of my performance testing is to see the differences in
network access of different virtual machines solutions running
Windows XP compared to a native Windows XP in the same
task.

Currently we are testing VMware and VirtualBox.

Hopefully this will allow us to decide if reality we are needing
to change the network over from 10/100 to a 10/100/100. The
application that is running is an in house developed database
that mostly small data packets. Or if the performance and
access issues are just a lack of grunt in the terminal PC's

Alan Smedley


0

Response Number 3
Name: Mechanix2Go
Date: June 14, 2009 at 03:27:52 Pacific
Reply:

@echo off

FOR /L %%f in (1,1,1000) do (
md %%f
echo abc > %%f\abc
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Smedley
Date: June 14, 2009 at 05:04:39 Pacific
Reply:

Thanks for the heads up on how to get this working, its brilliant and worked a treat.

So what I now have is as follows:

md ABC
cd ABC
for /L %%f in (1,1,1000) do (
md %%f
cd %%f
for /L %%g in (1,1,999) do echo %%g> %%g.cba
cd ..
)

And the output is a directory called ABC that has 1000 subdirectories each with 999 files that contain the number of the file this giving me a variable file length to also play around with in my testing.

Thankyou.

Alan Smedley


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Nested loop in batch file help

Nested loops in batch scripting www.computing.net/answers/programming/nested-loops-in-batch-scripting/12050.html

help needed with loop in batch file www.computing.net/answers/programming/help-needed-with-loop-in-batch-file/16897.html

Nesting variables in batch files ? www.computing.net/answers/programming/nesting-variables-in-batch-files-/14334.html