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.

In reply to Re^2: Age of directories again with a specified directory by dilip_val
in thread Age of directories again with a specified directory by dilip_val

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.