Environment for WinDOS, two points to note:
1, the default ActivePerl under the code is GBK, so you need to convert the string to GBK will not display garbled
2, to traverse the file directory, you need to exclude a special directory.
Complete code:
Copy Code code as follows:
#!/usr/bin/perl
Use strict;
Use warnings;
Use Encode qw/from_to/;
My $path = "e:/css design";
My $filecount = 0;
Sub Parse_env {
My $path = $_[0]; #or use my ($path) = @_; @_ similar to arguments in JavaScript
My $subpath;
My $handle;
If (-D $path) {#Does the current path be a directory?
If (Opendir ($handle, $path)) {
While ($subpath = Readdir ($handle)) {
If (!) ( $subpath =~ m/^\.$/) and! ($subpath =~ m/^ (\.\.) $/)) {
My $p = $path. " /$subpath ";
If (-D $p) {
Parse_env ($p);
} else {
+ + $filecount;
Print $p. " \ n ";
}
}
}
Closedir ($handle);
}
}
Return $filecount;
}
My $count = parse_env $path;
My $str = "Total Files:". $count;
From_to ($str, "UTF8", "GBK");
Print $str;
Run Effect chart: