my $d = shift
if (-d $d) {
my @d = <$d/*>
return 1 unless (@d > 0)
}
return 0
}
给你一个示例吧#!/usr/bin/perl
use warnings
$PATH="/path"
$DIR="dir"
opendir ETC, "${PATH}/${DIR}"
or die "can NOT open dir ${PATH}/${DIR} $!\n"
$dirnum=0
while ( readdir ETC ) {
next if /^\./
$dirnum++ if -d "${PATH}/$DIR/$_"
}
closedir ETC
print " The dir number in $PATH/$DIR is $dirnum "
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)