in reply to Recursive Subdirectories
However, so you understand the mechanics of directory recursion, as well as a bit of codestyle cleanup, I went ahead and modified your snippet to do what you ask without File::Find.
Update: Moved the report file open/close to the main function and corrected one of the comments.
Examine at your leisure:
#!/usr/bin/perl use strict; my $DIRSEP = '\\'; # FIXME This is for DOS/Windows. Make this mor +e portable. open(OUT, '>fileout.txt') or die "Couldn't open the " . "fileout.txt file for writing.\n"; &CheckFileAccess('.'); close(OUT); exit; sub CheckFileAccess() { my $BaseDir = $_[0]; opendir(HERE, $BaseDir); my @AllFiles = readdir(HERE); closedir(HERE); # Pass 1 for files, Pass 2 for directory recursion for (my $curpas = 0; $curpas < 2; $curpas++) { foreach my $Name (@AllFiles) { my $RelName = $BaseDir . $DIRSEP . $Name; if (!$curpas) { # Process Files only; if directory skip to next filena +me if(-d $RelName) { next } my $FileAcc = sprintf('%3d', -A $RelName); # Check for files that have been accessed in the last +10 days if ($FileAcc <= 10) { print "$RelName "; print "File was last Accessed ", $FileAcc, " days +ago\n"; # ------------------------------------------------ +--------- # DANGER printf could have produced interesting a +nd # unexpected results here, so I changed it to prin +t. # ------------------------------------------------ +--------- # printf OUT $Name . "\n"; print OUT $RelName . "\n"; } else { print $RelName, " File was Accessed more than 10 d +ays ago\n"; } } else { # Process Directories only if(-d $RelName) { # Skip danger directories if ($Name eq '.') { next } if ($Name eq '..') { next } # Good to go -- prepare for recursive call &CheckFileAccess($RelName); } } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Recursive Subdirectories
by pildor (Novice) on Apr 16, 2003 at 18:22 UTC |