-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrec.pl
More file actions
40 lines (34 loc) · 932 Bytes
/
rec.pl
File metadata and controls
40 lines (34 loc) · 932 Bytes
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
use Data::Dumper;
my $xxx = data_for_path(@ARGV);
dump_data_for_path('/etc', $xxx);
sub data_for_path {
my $path = shift;
if (-f $path or -l $path) { # files or symbolic links
return undef;
}
if (-d $path) {
my %directory;
opendir PATH, $path or die "Cannot opendir $path: $!";
my @names = readdir PATH;
closedir PATH;
for my $name (@names) {
next if $name eq '.' or $name eq '..';
$directory{$name} = data_for_path("$path/$name");
}
return \%directory;
}
warn "$path is neither a file nor a directory\n";
return undef;
}
sub dump_data_for_path {
my $path = shift;
my $data = shift;
if (not defined $data) { # plain file
print "$path\n";
return;
}
my %directory = %$data;
for (sort keys %directory) {
dump_data_for_path("$path/$_", $directory{$_});
}
}