At 03:10 PM 6/10/2001 -0400, Tim Musson wrote:
>Anyway, the requirement is to move all files older
>   than a specified age to another root folder while retaining the
>   entire directory structure.
>
>   For example:
>   p: = d:\users\User1\WinNT\System32\notepad.exe
>   We want to move it to
>   d:\Archive2CD\User1\WinNT\System32\notepad.exe
>
>   Yes, I realize notepad.exe is not a file that would need saving, but
>   it is a good example...
>
>   I have code that will produce a CSV file with:
>   path,filename,size,date,extension
>   "C:\WinNT\System32\","notepad.exe",5632,1999/3/27-15:7:10,exe
>
>   I don't find myself looking to modules to do things, but I am hoping
>   someone will have a good sugestion.

Not sure why you have the CSV file; I would just have done it all in one go 
to begin with:

use File::Find;
use File::Copy;
use File::Spec::Functions;
use File::Basename;
my $AGE = 2;  # days
finddepth(\&mirror, 'd:');

sub mirror {
   if (-M > $AGE) {
     (my $newdir = $File::Find::dir) =~ s/users/Archive2CD/;
     do_dir($newdir);
     copy($_, catfile($newdir, $_));
   }
}

sub do_dir {
   my $dir = shift
   return if -d $dir;
   my $parent = dirname($dir);
   do_dir($parent) unless -d $parent;
   mkdir $dir;
}


Untested, but looks reasonable.  Actually, it looks pretty cruddy with all 
that hair for Win32, but I'm in bed with the 'flu at the moment.

No core function for making a directory hierarchy?  How odd, but I don't 
see one.

Reply via email to