SteveO <> wrote:
> I am a Perl beginner
Have you seen the Posting Guidelines that are posted here frequently?
> to remove files older
> than 30 days, it works well EXCEPT that it leave the empty directories
> behind,
> #! Perl -w
> use Strict;
> use File::Find;
> $tempdir = "D:\\shared dirs\\temp Public";
That should fail to compile under strictures, you did not declare $tempdir.
use strict;
Case matters.
use warnings;
is better than the -w switch
If you use single quotes, then you won't have backslash the backslashes:
my $tempdir = 'D:\shared dirs\temp Public';
Or, better yet, use sensible slashes instead of silly slashes:
my $tempdir = 'D:/shared dirs/temp Public';
> find(\&Wanted, $tempdir);
You don't need a temporary variable at all:
find(\&Wanted, 'D:/shared dirs/temp Public');
> sub Wanted
Naming a subroutine that deletes files "wanted" is misleading,
seems like "unwanted" would be more accurate.
> @args = ("del", "/F", "/Q", "$_");
^^^
^^^
perldoc -q vars
What's wrong with always quoting "$vars"?
> system @args;
You can delete files and directories in native Perl:
perldoc -f unlink
perldoc -f rmdir
You need File::Find::finddepth instead of File::Find::find,
so that you can process the empty directory after removing
all of its files and subdirs.
So, something like this should get you started:
-------------------------
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
finddepth \&unwanted, 'playpen';
sub unwanted {
if ( -f ) {
unlink $_ or die "could not unlink '$File::Find::name' $!";
}
elsif ( -d ) {
rmdir $_ or die "could not rmdir '$File::Find::name' $!";
}
else {
warn "$File::Find::name is neither a plain file nor a directory\n";
}
}
-------------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas