-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirtree.pl
More file actions
executable file
·42 lines (39 loc) · 1.09 KB
/
dirtree.pl
File metadata and controls
executable file
·42 lines (39 loc) · 1.09 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
#!/bin/perl
#initialize dir_list & count
#$#dir_list = $[ - 1; # could use splice(@dir_list, 0, $#dir_list + 1) or @dirlist = ();
@dir_list = ();
$count = 0;
#start dir_list
if ($#ARGV == -1) {
push @ARGV, ".";
#print "ARGC $#ARGV :", join (":", @ARGV), ":\n"
}
@dir_list = @ARGV;
#print "dir list: $#dir_list :", join (":", @dir_list), ":\n";
#push (@dir_list, $ARGV[0]);
while ($count <= $#dir_list)
{
opendir (DIRECTORY, $dir_list[$count]);
#|| warn ("Can't open directory $dir_list[$count].\n");
$current = $dir_list[$count];
# make sure current ends with a '/'
$current .= "/" unless ($current =~ m|/$|); # could be m#/$#, etc.
while ($filename = readdir (DIRECTORY))
{
if (($filename ne ".") && ($filename ne "..")) {
if (( -d $current.$filename) && !(-l $current.$filename)) {
push (@dir_list, $current.$filename);
}
}
}
closedir (DIRECTORY);
$count++;
}
#print $#dir_list, " dl\n";
if ($#dir_list > 0) {
#print "Sorting...\n";
@dir_list = sort @dir_list;
print join ("\n", @dir_list), "\n";
} else {
print "$ARGV[0] is not a valid directory or has no subdirectories.\n";
}