Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Age of directories again with a specified directory

by arcnon (Monk)
on Nov 07, 2007 at 22:54 UTC ( [id://649590]=note: print w/replies, xml ) Need Help??


in reply to Age of directories again with a specified directory

dont know if this is what your looking for.
#!/usr/bin/perl use strict; use File::Find::Rule; use File::Copy; my $directory = 'F'; my $newlocation = 'a'; my @subdirs = File::Find::Rule->directory->in( $directory ); foreach my $dir (@subdirs){ #stat move("$dir", "$newlocation/$dir"); }

Replies are listed 'Best First'.
Re^2: Age of directories again with a specified directory
by dilip_val (Acolyte) on Nov 12, 2007 at 19:18 UTC
    Sorry about the delayed reply , actually the first piece of code works. but fails with the errpr below. issue is it tries to overwrite oldbackups but it should be creating files inside oldbackups. i need to append the sudirectory name within f:\test and append it to f:\oldbackups within the for loop. how do we achieve that?
    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 line 26.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://649590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found