-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilec.pl
73 lines (67 loc) · 1.37 KB
/
filec.pl
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl
use 5.10.1;
use warnings;
use strict;
use Time::HiRes qw(usleep);
my $Arg = $ARGV[0];
my $i = 0; # +1 for the current dir,
my $d = 0;
my $total = 0;
my $curpath = ".";
my $curDir = "~";
if ( $Arg && $Arg =~m/^(.\/|\/|~\/|.$|~$)/ ){
$curpath = $ARGV[0];
}
count($curpath);
sub count {
my $path = shift;
if(opendir my $DIR, "$path"){
my $current_count = 1;
print "\rCurrent count: $i Dir: $path \r";
foreach(readdir $DIR) {
if(m/^\.\.?$/){
next;
}
$current_count++;
$i++;
if( -d "$path/$_" ){
$total++;
usleep(2000);
count("$path/$_");
}
}
if($current_count > 500){
print "\n$current_count in $path";
}
$current_count = 0;
closedir $DIR;
}
}
sub count2{
my $dir;
if( "$curDir" =~ /^[0-9]/ ){
say "$d/$curDir";
} else {
say "$d$curDir";
}
my $path="$curpath";
opendir($dir, "$curpath");
foreach (grep { !/^\.\.?$/ && -f "$path/$_" || -l "$path/$_" } readdir $dir) {
if( "$_" =~ /^[0-9]/ ){
say "/$_";
} else {
say "$_";
}
}
opendir($dir, "$curpath");
foreach (grep { !/^\.\.?$/ && -d "$path/$_" && ! -l "$path/$_" } readdir $dir) {
$curpath = "$path/$_";
$curDir = "$_";
$d++;
$total++;
count2();
$d--;
}
closedir($dir);
}
say "You have $i files and $total of those are directories."