亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Perl腳本實(shí)現(xiàn)遞歸遍歷目錄下的文件

Original 2017-01-11 13:19:07 614
abstract:這篇文章主要介紹了Perl腳本實(shí)現(xiàn)遞歸遍歷目錄下的文件,本文直接給出實(shí)現(xiàn)代碼,代碼中包含明細(xì)注釋,需要的朋友可以參考下#!/usr/bin/perl -w use strict; use File::Spec;  local $\ ="\n";#當(dāng)前模塊的每行輸出加入換行符   my %o

這篇文章主要介紹了Perl腳本實(shí)現(xiàn)遞歸遍歷目錄下的文件,本文直接給出實(shí)現(xiàn)代碼,代碼中包含明細(xì)注釋,需要的朋友可以參考下

#!/usr/bin/perl -w
use strict;
use File::Spec; 
local $\ ="\n";#當(dāng)前模塊的每行輸出加入換行符  
my %options; 
#目錄路徑
$options{single_case} = '/home/jiangyu/src/pl/Example'; 
  my @cases;
  if (-d $options{single_case}) {#判斷目錄是否存在
    my @files;
    my $dh;
    push(@files, $options{single_case});
    while (@files) {
      if (-d $files[0]) {#若是目錄執(zhí)行以下操作
        opendir $dh, $files[0] or die $!;#打開目錄句柄,若失敗打印錯(cuò)誤信息
        @_ = grep { /^[^\.]/ } readdir $dh;#過濾掉以"."和".."的文件,即UNIX下的隱藏文件
        foreach (@_) {
          push(@files, File::Spec->catfile ($files[0], $_));#連接目錄名和文件名形成一個(gè)完整的文件路徑:
        }
        closedir $dh;
      }
      #若是文件直接壓入數(shù)組@cases中
      elsif ($files[0] =~ /\.t$/) {
        push(@cases, $files[0]);
      }
      shift @files;
    }
  }
  else {
    @cases = ($options{single_case});
  }  
print $_ foreach @cases;#打印文件列表

更多關(guān)于Perl腳本實(shí)現(xiàn)遞歸遍歷目錄下的文件請(qǐng)關(guān)注PHP中文網(wǎng)(ipnx.cn)其他文章!

Release Notes

Popular Entries