Concept99 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use File::Find; use strict; use Time::localtime; use File::Spec; my $cur = File::Spec->curdir; my $up = File::Spec->updir; my $dirtot; my ($dir, @parts, $error, $starttime, $runtime, $endtime, $runmin, $ye +ar, $month, $day, $tm, $date,$rootdir,$userdir,$slash); $tm = localtime; $year = $tm->year+1900; $month = $tm->mon+1; $day = $tm->mday; $date = "$month-$day-$year"; $slash = "//"; #Opens the input and output files open(IN, "< websize_input.txt") or die("Couldn't open websize_input.tx +t\n"); open(OUT, "> websize_out.csv") or die("Couldn't open websize_output.cs +v\n"); #Separates the newline delimited rows chomp ( @parts = <IN> ); #Used to calculate how long the program took to run $starttime = (time); #Prints headings print OUT "Path,User,MB,Date,Error?\n"; #Displays total for subdirectories foreach my $start (@parts) { my @dirs = &find_subdirs($start); foreach my $dir (@dirs) { ($rootdir,$userdir) = split /$slash/,$dir; print "\tWalking $dir\n"; my $total = 0; find sub { $total += -s }, $dir; $dirtot = $dirtot + $total; #Used for determining tota +l directory size $total = ($total / 1024) / 1024; #Converts to MB $total = sprintf("%0.2f", $total); #Formats output to 2 de +cimals print OUT"$rootdir,$userdir,$total,$date,$!\n"; } $dirtot = ($dirtot / 1024) / 1024; #Converts to MB $dirtot = sprintf("%0.2f", $dirtot); #Formats total to 2 deci +mals print STDERR "$start: No subdirectories\n" unless @dirs; } print "\nOutput created."; sub find_subdirs { my $start = shift; unless(opendir(D, $start)) { warn "$start: $!\n"; next; } my @dirs = map { -d "$start/$_" && !-l "$start/$_" && $_ ne $cur && $_ ne $up ? "$start//$_" : () } readdir(D); closedir(D); @dirs; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Find subdirectory limit?
by BrowserUk (Patriarch) on Jun 26, 2003 at 19:37 UTC | |
|
Re: File::Find subdirectory limit?
by tilly (Archbishop) on Jun 26, 2003 at 19:40 UTC |