Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Script to recurse directory down 2 levels and list directors by last modified and size

by pauloke (Initiate)
on Dec 04, 2008 at 17:55 UTC ( [id://728044]=perlquestion: print w/replies, xml ) Need Help??

pauloke has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am new to perl (and lower level languages in general) so please be gentle with me.

I have a shared network folder that I need to monitor on a regular basis to ensure it doesn't become full. It stores project builds. Each project has its own folder containing multiple builds.

I need to produce a script that could initially produce a txt file maybe or just print to screen and list of build folders that are older than a given date and purhaps over a given size. So I will need to recurse through all project folders calculating build folders sizes and determine which match a given criteria.

without knowing much about perl I have become stuck very quickly and not know how to proceed. Do I use File::Find or do I use opendir - readdir - closedir? or is there a better solution.

Any help would be appreciate - I am not asking for someone to produce the script for me. Just point me in the right direction with example, code snippets and tutorials if you know or just and explanation of an algorithm.

I am working within a Win32 environment.

Hope you can help.

Thanks in advance.

  • Comment on Script to recurse directory down 2 levels and list directors by last modified and size

Replies are listed 'Best First'.
Re: Script to recurse directory down 2 levels and list directors by last modified and size
by n3toy (Hermit) on Dec 04, 2008 at 18:27 UTC
    This might be a good place to start. It has some good code examples for recursive searches.

    Jamie
Re: Script to recurse directory down 2 levels and list directors by last modified and size
by zentara (Archbishop) on Dec 04, 2008 at 20:35 UTC
    You might find File::Find::Rule easy for depth control:
    #!/usr/bin/perl use warnings; use strict; use File::Find::Rule; my $word = shift || 'perl'; # find all the files of a given directory my $directory = shift || '/home/zentara'; my $depth = shift || 3; my $rule1 = File::Find::Rule->new; $rule1->maxdepth($depth); $rule1->file; $rule1->grep(qr/\Q$word\E/); #$rule->name( '*.pm' ); my @files = $rule1->in($directory); print "@files\n";

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Script to recurse directory down 2 levels and list directors by last modified and size
by kennethk (Abbot) on Dec 04, 2008 at 18:43 UTC

    I would suggest using the stat function on your directory or file handles - note the element ctime corresponds to creation time on MS systems.

    You might also consider using a revision control framework in place of a community network drive.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://728044]
Approved by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-20 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found