Greetings,
having only been programming with Perl for a week. I decided to write a Perl program to check for files on my Windows 2K server that have not been accessed in a certain amount of time (i.e. 10 days in this example) and store there names in a log file. Everything works great, expect I can not figure out how to read the filenames in subdirectories. I am using Perl 5.8.0 under Windows XP. Any help would be greatly appreciated!
Here is my novice code:
opendir(HERE, '.');
open(OUT, '>fileout.txt') or die "Couldn't open the " .
"fileout.txt file for writing.\n";
@AllFiles = readdir(HERE);
foreach $Name (@AllFiles) {
# If directory skip to next filename
if(-d $Name) { next }
$FileAcc = sprintf('%3d', -A $Name);
# Check for files that have been accessed in the last 10 days
if ($FileAcc <= 10) {
print "$Name ";
print "File was last Accessed ", $FileAcc, " days ago\n";
printf OUT $Name . "\n"; }
else { print $Name, " File was Accessed more than 10 days ago\n"; }
}
closedir(HERE);
close(OUT);
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.