I use the following as a starting code for any recursive file task:

#!perl -w use strict; $0 =~ s!^.*[\\/]([^\\/]+)$!$1!; die "Syntax: $0 [file|dir]...\n" unless defined $ARGV[0]; use Time::Local; # just for this example. my @pend = @ARGV; # pending list of files and dirs while (my $d = shift(@pend)) { if (-d $d) { dir($d); } else { file($d); } } exit; sub file { my ($f) = @_; # process a file, for example: my $m = (stat($f))[9]; print "$f\t$m\t" . date($m) . "\n"; } sub dir { my ($d) = @_; opendir(D, $d) || die; while (my $f = readdir(D)) { next if $f =~ /^\.\.?$/; # skip . and .. my $n = "$d/$f"; if (-d $n) { push(@pend, "$n"); # enqueue dir } else { file($n); # process file now!!! } } closedir(D); } sub date { my ($t) = @_; my ($ss,$mm,$hh,$dd,$nn,$yy) = (localtime($t))[0..5]; return sprintf("%04g-%02g-%02g %02g:%02g:%02g", ($yy<70?2000:1900)+$yy, $nn, $dd, $hh, $mm, $ss); }

In reply to Re: Search for oldest file in directories and its subdirectories by vitoco
in thread Search for oldest file in directories and its subdirectories by p_boarder

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.