Merge branch 'master' of https://Governor-Tarkin@bitbucket.org/Governor-Tarkin/swg...
[swg-src.git] / tools / getFileSizeInDirectoryTree.pl
blob0583f5edaa74cdc335af356a418f964fc48ce45d
1 # Syntax: perl getFileSizeInDirectoryTree.pl [-d] [directory [pathname_regex]]
3 use strict;
4 use File::Find;
6 my $debug = 0;
7 my $pathnameMustMatchRegex;
9 # Subroutine called by File::Find.
10 sub processFile
12 print STDERR "testing [$File::Find::name]..." if $debug;
14 if (!defined($pathnameMustMatchRegex) || $File::Find::name =~ m/$pathnameMustMatchRegex/)
16 print STDERR "matched, printing.\n" if $debug;
18 my @fileStat = stat;
19 my $formattedName = $File::Find::name;
20 $formattedName =~ s!\\!/!g;
21 print "$fileStat[7] $formattedName\n";
23 else
25 print STDERR "no match, skipping.\n" if $debug;
29 # Check for help.
30 if (defined($ARGV[0]) && $ARGV[0] =~ m/-h/)
32 print "Syntax: getFileSizeInDirectoryTree.pl [directory [pathname_regex]]\n";
33 print "\tpathname_regex is a Perl-compatible regular expression, matches all if not specified.\n";
34 exit 0;
37 # Check for debug.
38 if (defined($ARGV[0]) && $ARGV[0] =~ m/-d/)
40 $debug = 1;
41 print STDERR "\$debug = 1\n";
42 shift @ARGV;
45 # Setup directory.
46 my @directories = ($ARGV[0]);
47 $directories[0] = '.' if !defined($directories[0]);
48 print STDERR "directories = [@directories]\n" if $debug;
50 # Setup regex.
51 $pathnameMustMatchRegex = $ARGV[1] if defined($ARGV[1]);
52 $pathnameMustMatchRegex =~ s/[\'\"]//g if defined($pathnameMustMatchRegex);
53 print STDERR "pathnameMustMatchRegex = [$pathnameMustMatchRegex]\n" if ($debug && defined($pathnameMustMatchRegex));
55 # Do the find.
56 File::Find::find(\&processFile, @directories);
58 # Done.