-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFindJs.pm
More file actions
55 lines (49 loc) · 1.6 KB
/
FindJs.pm
File metadata and controls
55 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# recurse into a root folder provided to the constructor to find all .js files.
# the main method here is getJsFiles which starts the recursive find
package FindJs;
#constructor
sub new {
my($type) = $_[0];
my($this) = {};
$this->{'root'} = $_[1];
bless($this, $type);
return($this);
}
# Recurse into all folders under root to find only .js files
# hard coded skipping of any content in any . (hidden) folders
sub getJs
{
my $this = $_[0];
my $dirname = $_[1];
opendir(DIR, $dirname);
my(@names) = readdir(DIR);
closedir(DIR);
# Loop thru directory, handle files and directories
my($name);
foreach $name (@names) {
chomp($name);
my($path) = "$dirname/$name";
if( -d $path ){ # it's a folder
if(($name ne "..") && ($name ne ".")) {
if($path !~ /\/\./) { # hard code: filter out hidden folders based on a /. pattern
$this->getJs($path); # recurse
}
}
}
else { # it's a file
if($path =~ /\.js$/) { # only cache .js files for processing later
$strip = $this->{'root'};
$path =~ s/$strip//; # strip all but the file part of path
$path =~ s/^\///; # strip off leading /
push(@{$this->{'jsFiles'}},$path);
}
}
}
return;
}
sub getJsFiles {
my($this) = $_[0];
$this->getJs($this->{'root'});
return @{$this->{'jsFiles'}};
}
return(1); #package files must always return 1.