dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Create new folder and "n" number of Sub folders

  1. #1
    Join Date
    Jun 2009
    Posts
    3

    Create new folder and "n" number of Sub folders

    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

  2. #2
    Join Date
    Sep 2008
    Posts
    408
    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).

  3. #3
    Join Date
    Jun 2009
    Posts
    3
    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?

  4. #4
    Join Date
    May 2009
    Posts
    64
    Quote Originally Posted by shailesh143 View Post
    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.

  5. #5
    Join Date
    Jun 2009
    Posts
    3
    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?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles