I don't have my regular computer with me to test this, but when I want to
create a directory if it doesn't exist, I do something like this:

$fullpath = "c:\\temp\\test\\level2";
@path = split /\\/,$fullpath;
$dir = shift @path;
foreach(@path){
   $dir = $dir."\\$_";
   if(!-e $dir){
      mkdir($dir);
   }
}
    

-----Original Message-----
From: John Marion
To: [EMAIL PROTECTED]
Sent: 3/19/02 6:49 PM
Subject: directory creation help

Well I changed the make up of lines 137 and 138.  This is where the
problem
lies.  I cannot make a drecotry that is part of the list that I use (ie:
\apps\dll ) and then copy all the associated dll files into it.

Anything would be greatly appreciated.

John


#!C:\NTRESKIT\perl
#use File::Copy;
#does C:\ntapps\common\C exist?
#add user notification using Win32::Console

$startdir = "\\ntapps\\common\\c";

@filespec = ('exe', 'dll');

#@filedelete = glob ("\\junk\\save\\*.*");

@filedelete = system ("del "."$savedir"."*.* /Q");

#@cmd = ('dir');

$savedir  = 'C:\junk\save';

#sub searchDirectory;
#sub builddirectory;



if (-e "\\ntapps\\common\\c"){
        #Find all EXE's and DLL's
        open (OUTFILE, '>\ntapps\log\mv_common_c.lst');

        searchDirectory($startdir,"",@filespec);

        #removing files from junk\save
        #unlink @filedelete;
        #rename files using the system
        system ("rename" ,'C:\junk\save\*.*', '*.old');

        close (OUTFILE);
        movefiles();

}else

        print "missing \n";
}


# use THIS TO FIND EXE'S AND DLL's
sub searchDirectory {
        # $startdir is a path name, @filespec is a list of file
extensions only(ie:
exe, dll, ...)
        local($basedir,$startdir,@filespec) = @_;
        local(@lines);
        local($subdir);
        local($lvl_counter);
        local($list_length);

        #print "got to search directory\n";
        if(opendir (DIR,$basedir.$startdir))
        {
          @lines = readdir (DIR);
          closedir (DIR);
          $lvl_counter = 2;
          $list_length = ( scalar @lines );
            while ($lvl_counter < $list_length)
            {
              $subdir = $startdir."\\".$lines[$lvl_counter];
              if(!searchDirectory($basedir,$subdir,@filespec))
              {
        
processnames($startdir.'|'.$lines[$lvl_counter],@filespec);
              }
              $lvl_counter++;
            }
        }else {
                return 0;
        }
        return 1;

}


sub processnames {
        # Give the value passed to this sub a sensible name.
        my ($filename,@filespec) = @_;

        $match = join '|', @filespec;
        if ($filename =~ /($match)$/i) {
                print (OUTFILE "$filename\n");

        }
}


sub movefiles {
        local ($name, $path, $filename, $topath);
        #This is moving the files on the list we created to junk\save
        #open input file
                print "inputlist\n";
        open (INPUTLIST, '<\ntXpps\log\mv_common_c.lst');
        foreach $file (<INPUTLIST>) {
                ($path,$name) = split (/\|/, $file);
                if (!-e  $savedir.$path."\\" && !$path == "" ) {
                        $topath = $savedir.$path;
                        print "path:$path\n";
                        print "making directory: $topath\n";
                        #mkdir ($topath, 0777) || die "cannot mkdir
$topath: $!";
                        #`C:\\john\\ldapps\\perl\\buildir.pl $savedir,
$path`;
                        ##closedir dumb;
                }
                if (!-d $basedir ) {print "ouch\n" }
                $command = 'copy '.$startdir.$path."\\".$name.'
C:\junk\save'.$path;
                print "$command\n";
                print "path:$topath, name:$filename\n";
                system ($command);
                last;

        }
        close (INPUTLIST);
}



#this assumes that basedir exists
sub builddirectory {
        local ($basedir, @path) = @_;
        local ($directory);
        @sublist =  ($path <1) ? (split(/\\/, $path[0])) : (@path) ;
        print "$#path, $#sublist, @path, @sublist\n";
        foreach $directory (@sublist) {
          if ($directory =~ /\s/) { next; }
          if (!-e $basedir.'\\' .$directory) {system (start, md
'C:\junk\save'.
'\\' .$directory);}
          $basedir .= '\\'.$directory;
          #if (!-e $basedir.'\\' .$directory) { mkdir($basedir. '\\'
$directory,
0777); }
          #$basedir .= '\\'.$directory;
          print "$basedir\n";

        }


}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to