dilip_val has asked for the wisdom of the Perl Monks concerning the following question:
use warnings; use File::Copy; use File::Spec::Functions qw( catfile ); use File::Find; my $dir = 'F:\\test'; my $newlocation = 'F:\\oldbackups'; opendir(my $dh, $dir) or die("Can't open directory \"$dir\": $!\n"); my @dirs; while (defined(my $fn = readdir($dh))) { next if $fn eq '.' || $fn eq +'..'; my $qfn = catfile($dir, $fn); if (-d $qfn && -M $qfn > 0) { push @dirs, $qfn; # or $fn } } foreach ( +@dirs) { print("Directory to be moved : $_\n"); } foreach my $dr (@dirs){ move("$dr", "$newlocation") || die "$!"; print "Moved $dr to $newlocation\n"; } output: D:\Software\scripts>cqperl test2.pl Directory to be moved : F:\test\New Folder (2) Directory to be moved : F:\test\New Folder (3) Directory to be moved : F:\test\New Folder (4) Directory to be moved : F:\test\test2 Permission denied at test2.pl li +ne 26.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to append a sub directory name alone to an existing dir path ?
by ikegami (Patriarch) on Nov 13, 2007 at 21:50 UTC |