I don’t know why I am having such a tough time creating a directory.

 

I have the following code, but for some reason I can’t create a directory:

 

#!/usr/bin/perl -w

# Microsoft Windows Win32

 

use strict;

use File::Find;

 

my $i;

my $cs;

my @myArray;      # array to hold matches

my $Month;        # variable to hold month value (i.e. '2002_10')

my $NewDirName;   # variable to hold the string to point to the new directory location

 

find(\&Display,'.');

 

sub Display {

            # please let me know if there is a better way to do this

            # I am just trying to extract the 'month' out of the file name

            # I think I am doing extra work . . .

            @myArray = ($File::Find::dir =~ /^\.\/(\d{4}_\d{2})/);

            $Month = $1;

            $NewDirName = "/imgs/" . $Month . "/";

            if (!(-e $NewDirName)) {                              # make a new directory

                  chdir "D:\\";                                   # go to D:

                  mkdir $NewDirName;                              # make the directory

                  print "created " . $NewDirName . "\n";          # report success

            }

}

 

My Directory structure is like:

07/13/2002  09:53 AM    <DIR>          1999_07

07/13/2002  09:53 AM    <DIR>          1999_08

07/13/2002  09:53 AM    <DIR>          1999_09

07/13/2002  09:53 AM    <DIR>          1999_10

07/13/2002  09:53 AM    <DIR>          1999_12

07/13/2002  09:53 AM    <DIR>          2000_01

. . ..

 

One of the errors I keep getting is:

>Can't cd to (./) 2001_10 : No such file or directory

 

any ideas would be really appreciated . . .

 

tim

Attachment: smime.p7s
Description: application/pkcs7-signature

Reply via email to