我有一段代码可以找到给定目录中的所有.txt文件,但我不能让它查看子目录.
我需要我的脚本做两件事
例如,我有一个目录
C:\abc\def\ghi\jkl\mnop.txt
Run Code Online (Sandbox Code Playgroud)
我编写指向路径的脚本C:\abc\def\.然后它会遍历每个子文件夹并查找该文件夹中的mnop.txt任何其他文本文件.
然后打印出来 ghi\jkl\mnop.txt
我正在使用它,但它实际上只打印出文件名,如果文件当前在该目录中.
opendir(Dir, $location) or die "Failure Will Robertson!";
@reports = grep(/\.txt$/,readdir(Dir));
foreach $reports(@reports)
{
my $files = "$location/$reports";
open (res,$files) or die "could not open $files";
print "$files\n";
}
Run Code Online (Sandbox Code Playgroud) 我知道我在这里遗漏了一些简单的东西,但我无法弄明白并且谷歌无法正常工作
我试图使用该值,$F但它不起作用.我将省略一些代码.我得到一个错误基本上说$f需要一个特定的包名称
sub captureFile()
{
my $F = $File::Find::name;
if ($F = ~/txt$/)
{
$F=~ s:(.*)(\/reports\/.*):$2:;
loadEnvironmentProperties($F);
}
}
sub loadEnvironmentProperties()
{
print $F;
}
Run Code Online (Sandbox Code Playgroud) perl ×2