directory tree 
Author Message
 directory tree

Quote:

>Does anyone have a snippet of perl coding that will create a list of
>subdirectories under a given directory (walk the directory tree)?

Investigate the File::Find module, either to use directly or as a sample
of code.

Mike Guy



Fri, 16 Jun 2000 03:00:00 GMT  
 directory tree

I'll part with a code snippet from the book here (sorry for
any formatting ugliness ... due to copy/paste from Acrobat).
Hopefully it dinna get garbled in transmission:

sub count_recurse {
  local *DIRH;

  $$dir_ct_ref++;

  opendir DIRH, $dir_name or die "couldn't open $dir_name: $!";

  closedir DIRH;


    next if $file eq '.' or $file eq '..';
    if (-f "$dir_name/$file") {
      $$file_ct_ref++;
      next;
    };
    next unless -d "$dir_name/$file";
    next if -l "$dir_name/$file";
    count_recurse($file_ct_ref,
    $dir_ct_ref, "$dir_name/$file");
  }

Quote:
}

$file_ct = $dir_ct = 0;
count_recurse \$file_ct, \$dir_ct, ".";
print "$file_ct files, $dir_ct dirs\n";

        -joseph
         http://www.effectiveperl.com

Quote:

> Does anyone have a snippet of perl coding that will create a list of
> subdirectories under a given directory (walk the directory tree)?



Sat, 17 Jun 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. A tree program recursing the directory tree

2. Traversal of a directory tree with housekeeping per directory

3. comparison of directory-trees with Perl 5

4. Output dynamic interactive graphical directory tree from perl to html

5. Directory tree

6. tool to pretty print directory trees?

7. how to mirror directory trees

8. thicken.pl -- unflatten a directory tree

9. walking a directory tree

10. WANTED: Perl code for a Directory Tree

11. count lines in files in a directory tree

12. xcopy a directory tree

 

 
Powered by phpBB® Forum Software