in reply to Count folder/files in directory
use strict; use File::Find; my $source = 'c:/directory'; my $folders = 0; my $files = 0; $File::Find::dont_use_nlink = 1; # to fix a bug in File::Find File::Find::find( sub { if (-f $File::Find::name) { $files++ } elsif (-d $File::Find::name) { $folders++ }; }, $source ); print "Summary of $source\n"; print "Folders: $folders\n"; print "Files: $files\n";
Also note how my code has a different background and a "download" link. This is because I wrapped it in <code>...</code> tags instead of using <pre> tags. PRE tags are kind of frowned upon here - see the Writeup Formatting Tips for further information.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Count folder/files in directory
by kyle (Abbot) on May 22, 2008 at 16:10 UTC | |
by Corion (Patriarch) on May 22, 2008 at 16:14 UTC | |
by runrig (Abbot) on May 22, 2008 at 16:32 UTC |