my @files
files('.', \@files)
print "$#files @files\n"
my @local
@local = glob("./*")
print "$#local @local\n"
sub files {
my $path = 雀陪shift
my $arr = shift
opendir(my $H, 局迟$path) || return
my @f 顷腊蠢= readdir($H)
close($H)
for my $f(@f) {
my $p = "$path/$f"
next if ($f =~/^[.]+$/)
if (-f $p) {
push @$arr, $f
}
else {
files($p, $arr)
}
}
}
用perl获取某一文件所在路径,参陵兄侍考代尘模码如下:use Cwd 'abs_path'
print abs_path($0)."\n"尺吵
man Cwd
NAME
Cwd - get pathname of current working directory
SYNOPSIS
use Cwd
my $dir = getcwd
use Cwd 'abs_path'
my $abs_path = abs_path($file)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)