I *just* started using perl but I trying to learn. Explainations of what is wrong are more useful than simple fixing the problem for me.

I have seen many posts about proforming and function on every file in a directory but have seen none about working on the directory level.

I need a script that:
(UNIX only) Recurses through a directory structure and checks if more than half of the file in that directory have been used in the past 180 days. The path of directory which are predominately unused is apprended to a list of directory which will be used to archive them.

There area I'm most concerned with is my recurse functions itself. And if there is a more efficent way of doing this please explain that as well.

#!usr/bin/perl # Author: Ryan Scadlock # Date: 6 July 2002 use strict; my $path = './'; die "The file $base_file does not exist!\n" if (!-f $base_file); # Initiate the recursion &RecurseDirs($path); rm temp; print "The result can be found at Results file in this dir"; #### SUBROUTINES SECTION #### # Function that recurses through the directory tree sub RecurseDirs { my ($path) = @_; my $file; #Variable for a file foreach $path($path){ opendir (DIRECTORY, $path) || die "Can't read $path\n"; if (-d "$path$file/") { #If it's a directory... # Recurse again through this directory &RecurseDirs("$path$file/"); my $unused = 0; #Counter for how many files are accessed my $count = 0; #Counter for how many files are in dir # Count unused files in dir $path find -type f -atime +180 >temp.txt; $str = wc temp -l; $unused = int::substr($str, 0, 1); #returns the first characte +r as an int # Count files in dir $path find -type f >temp.txt; $str = wc temp -l; $count = int::substr($str, 0, 1); #returns the first character + as an int # Compare # Yes: write full dir path to file if (($unused * 2) > $count){ $path >>result.txt; } } closedir (DIRECTORY); } }

In reply to recursive directory question by Aquilo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.