From: SteveO on
I am a Perl beginner and I hve writen this script to remove files older
than 30 days, it works well EXCEPT that it leave the empty directories
behind, can anyone help me look for empty directories and remove them
as well?
TIA,
Steve

#! Perl -w
use Strict;
use File::Find;
$tempdir = "D:\\shared dirs\\temp Public";
find(\&Wanted, $tempdir);
sub Wanted
{
#Do not scan Purchasing or Budget
return $File::Find::prune = 1 if $_ eq "Purchasing - Do Not Remove";
return $File::Find::prune = 1 if $_ eq "BUDGET";
# only on files older than 30 days
if ( ( -M $_ ) > 30 ) {
@args = ("del", "/F", "/Q", "$_");
system @args;
}
}

From: Tad McClellan on
SteveO <stevehobrien(a)hotmail.com> 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
tadmc(a)augustmail.com Perl programming
Fort Worth, Texas
From: A. Sinan Unur on
Josef Moellers <josef.moellers(a)fujitsu-siemens.com> wrote in news:du9dek
$k93$1(a)nntp.fujitsu-siemens.com:

> Keith Weller wrote:
>> Tad McClellan <tadmc(a)augustmail.com> trolled:
>>
>>>SteveO <stevehobrien(a)hotmail.com> wrote:
>>
>>
>>>>I am a Perl beginner
>>
>>
>>>Have you seen the Posting Guidelines that are posted here frequently?
>>
>>
>> Posting guidelines? This is not a moderated group.

....

> Again, feel free to insult, but expect little help in that case.

I just wanted to make sure everyone realizes that these posts have fake
From: lines, and, in this particular case, it wasn't Keith Keller who
posted the complaint about the posting guidelines.

See also other recent posts which are made to look like they are coming
from Tad.

Sinan

--
A. Sinan Unur <1usa(a)llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

From: Paul Lalli on
Tad McClellan wrote:
> SteveO <stevehobrien(a)hotmail.com> wrote:
> > #! 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.

And it would, if the OP was not using a broken operating system.
Windows will not complain about the lack of a Strict.pm file, as it
considers Strict.pm to be the same as strict.pm. It will even require
the code from strict.pm. But it will not carry out any of the
instructions in the strict pragma.

> use strict;
>
> Case matters.

Indeed.

Paul Lalli

From: A Sinan Unur on
A. Sinan Unur <1usa(a)llenroc.ude.invalid> trolled:

> I just wanted to make sure everyone realizes that these posts have
> fake From: lines, and, in this particular case, it wasn't Keith
> Keller who posted the complaint about the posting guidelines.

No, it was Keith Weller. Having reading problems? If you hadn't
deleted the attribution line, you could have seen that for yourself.

Duh.

> See also other recent posts which are made to look like they are
> coming from Tad.

What about posts that look like they are coming from you?

If you're a "friend" of Keller's and McLellan's, then you're not
worth a response, are you?

Please put yourself in a killfile so I won't be able to read your
remarks.

Thanks, troll.

cordially, as always,

rm