Apologies for not posting the code - this has been constructed of code from different forums and a little tweaking. No comments as yet.

#!/usr/local/bin/perl -w ($#ARGV != 2) or die "Usage: $0 [directory] [rentention period in week +s]\n"; use strict; use warnings; use File::Find; use File::stat; use Time::localtime; use Time::Local; my ($dir_path, $ret) = @ARGV; my $rdate = time - ($ret * 24 * 60 * 60); my $dir_depth = 1; my %size; my %date; find( { preprocess => \&preprocess, wanted => \&wanted,} , $dir_path); my @sorted = sort {$size{$b} <=> $size{$a}} keys %size; print "\nList of directories older than: ".ctime($rdate)."\n\n"; printf "%-10s %-24s %s", "Size", "Modified Date", "Directory Path\n\n" +; foreach (@sorted) { printf "%10d %s %s\n", $size{$_}, ctime($date{$_}), $_; } sub preprocess { my $depth = $File::Find::dir =~ tr[/][]; return @_ if $depth < $dir_depth; return grep { not -d } @_ if $depth == $dir_depth; return; } sub wanted { my $depth = $File::Find::dir =~ tr[/][]; my $mod_date = (stat($File::Find::name)->mtime); if ( ($mod_date < $rdate) && ($depth == $dir_depth)) { $size{$File::Find::name} = ProcessDir($File::Find::name) if -d +; $date{$File::Find::name} = $mod_date if -d; } return if $depth == $dir_depth; } sub ProcessDir { my( $Path ) = @_; my @DirList; my $DirSize = 0; if( opendir( DIR, $Path ) ) { while( my $Object = readdir( DIR ) ) { next if( "." eq $Object || ".." eq $Object ); my $ObjectPath = "$Path\\$Object"; if( -d $ObjectPath ) { push( @DirList, $ObjectPath ) } else { $DirSize += -s $ObjectPath; } } closedir( DIR ); } foreach my $ObjectPath ( @DirList ) { $DirSize += ProcessDir( $ObjectPath ); } return( $DirSize ); }

It is not complete but I was wondering if the sub ProcessDir could be more efficient.

I will investigate glob.

Cheers
P


In reply to Re^2: using File::Find within File::Find by pauloke
in thread using File::Find within File::Find by pauloke

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.