First - thanks for the help and comments.
Second - after reviewing the responses, suggestions, and doing some more studying, I think I am on the right track with my array. However, I am receiving "or die" message as my script executes. I have included a cleaned up version below for your information. It appears to be correct, and ran before I added the array. The error message states the correct array element so, I know that part is working. The directories do exist and contain other files and directories. Please take a look and point me in the right direction. Thanks in advance.
#!/usr/local/bin/perl
open (FILE, "/Scripts/rotlog");
my @lines = <FILE>;
close FILE;
foreach $element (@lines) {
# open the directory for reading
opendir(REP, "$element") || die "Cannot open the directory $element $
+! ";
open(REMLOG,">/Scripts/dir-removed.log"); # open a file to keep as a
+log of directories removed.
print REMLOG "Directories removed this date : ",`date`, "\n"; # Place
+a heading in the file.
# list the contents of the directory. These should be directories.
while ($name = readdir(REP)) {
if (-M $name >= 10) {
print "$name\n" unless($name eq "images"); #
print REMLOG "$name\n" unless($name eq "images"); #do not remove t
+he images directory
`rm -r $name` unless($name eq "images"); # THIS WILL REMOVE THE D
+IRECTORY AND ALL OF ITS subdirectories and Files.
}
}
close remlog;
closedir(REP)
}
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.