On Jun 18, Pete Emerson said:
>This isn't successfully going through all of the files. Is the recursion perhaps
>causing problems because DIR keeps getting redefined with each level of
>recursion, or am I missing something else?
Right. The solution is to localize the dirhandle.
>
>sub Purge {
Jeff 'japhy' Pinyan wrote:
> You could go over the entries from readdir() one at a time:
>
> opendir DIR, $dir or die "can't read $dir: $!";
>
> while (defined(my $file = readdir DIR)) {
> next if $file eq '.' or $file eq '..';
> my $full = "$dir/$file";
> # ...
> }
>
> closed
On Jun 18, Pete Emerson said:
>Jeff 'japhy' Pinyan wrote:
>
>> ### ick -- use opendir() and readdir(), or glob()
>
>Okay, sounds good. I'm not quite sure how to use glob. opendir works:
> opendir(DIR, "$dir");
> my @ls=readdir(DIR);
> closedir(DIR);
>
>except I get the directories . and .. , w
Jeff 'japhy' Pinyan wrote:
> ### ick -- use opendir() and readdir(), or glob()
Okay, sounds good. I'm not quite sure how to use glob. opendir works:
opendir(DIR, "$dir");
my @ls=readdir(DIR);
closedir(DIR);
except I get the directories . and .. , which doesn't cut it for recursion.
Is the
#!/usr/bin/perl -w
use strict;
use File::stat;
my $startingdir="/tmp"; # could use $ARGV[0] here to make it more
my $cutoff=5;# could also pass in the cutoff from
&Purge($startingdir);
## Subroutines #
sub Purge {
(my $dir)=@_;
### this is more normal
Hey Pete,
Not sure why you want to call ls when Perl can do the same thing. I
asked the list a similar question (I needed to move old files to a
different top directory - retaining the path to each file) a couple
weeks ago and got the following. (btw, I run this on Win32, so you
will need to cha
I've written a short program to recursively delete files/directories
that haven't been modified in a certain length of time. It appears to
work, but in the interest of improving my code/coding skills, I'd like
to get any/all comments and criticisms, particularly about the way
I handled getting the