環境為windos,需要注意的兩點:
1、預設activeperl下的採用的編碼是gbk,所以需要將字串轉為gbk才不會顯示亂碼
2、遍歷檔案目錄時,需要排除特殊的目錄.和..
完整的**:
#!/usr/bin/perl
2:use strict;
3:use warnings;
4:use encode qw/from_to/;
5:
6: my $path = "e:/css design";
7: my $filecount = 0;
8:
9: sub parse_env else
26: }
27: }
28: closedir($handle);
29: }
30: }
31:
32:return $filecount;
33: }
34:
35: my $count = parse_env $path;
36: my $str = "檔案總數:".$count;
37: from_to($str, "utf8", "gbk");
38:
39:執行效果圖:print $str;
perl 遞迴地遍歷目錄下的檔案
usr bin perl w usestrict use file spec local n 當前模組的每行輸出加入換行符 my options 目錄路徑 options home jiangyu src pl example my cases if d options while files re...
perl 遞迴地遍歷目錄下的檔案
usr bin perl w usestrict use file spec local n 當前模組的每行輸出加入換行符 my options 目錄路徑 options home jiangyu src pl example my cases if d options while files re...
perl遍歷檔案
本貼對三種遍歷資料夾方法比較。1.使用file find 2.遞迴遍歷。遍歷函式為lsr 3.使用佇列或棧遍歷。遍歷函式為lsr s 1.use file find copy to clipboard code usr bin perl w file find.pl author 路小佳 licen...