Click to See Complete Forum and Search --> : Create new folder and "n" number of Sub folders


shailesh143
06-23-2009, 12:34 AM
HI all,

#!/usr/bin/perl
foreach $i (1..5)
{
print " Creating directories under C: drive \n";

mkdir("C:/Er");
mkdir("C:/Op");
mkdir("C:/Ip");
mkdir("C:/Ima");
mkdir("C:/Imp");
# Till above lines it works
for($i=0;$i<=100;$i++)
{
mkdir('C:/Ip/Batch$i');
}

}


With this Script i am able to create folders, but in For loop, i want to create 100 folders with name "Batch1, Batch2.....Batch100" Its creating only one folder with name "Batch$i".
How do i do it?
Kindly help me.
and correct the code.

Regards,
Shail's

Shorts
06-23-2009, 12:54 AM
Change

mkdir('C:/Ip/Batch$i');

to

mkdir("C:/Ip/Batch$i");

or

mkdir('C:/Ip/Batch'.$i);

In single quotes it doesn't parse in variables (PHP does the same thing).

shailesh143
06-23-2009, 04:30 AM
Heyyyy ya.

Thanks pal. You are a gem sir hats off. the problem got solved.
But one more think if you could help,
i want to copy some amount of Images/Files in each sub folders which got created using above script can you please help me?

perl_diver
06-23-2009, 01:25 PM
Heyyyy ya.

Thanks pal. You are a gem sir hats off. the problem got solved.
But one more think if you could help,
i want to copy some amount of Images/Files in each sub folders which got created using above script can you please help me?

It looks like you are pretty new to perl, but if you want to dip in you can look at the File::Path and File::Copy modules which can do all the stuff you want. Or get help coding it yourself. :)

shailesh143
06-29-2009, 09:01 AM
Yes you are correct i am not perfect swimmer in PERL. or even a Diver :)
Anyways thanks for the suggestion.
Can you please write it for me?