我有一个文件夹,里面有很多子文件夹。在这些子文件夹中,我有许多要读取的 .html 文件。我已经编写了以下代码来做到这一点。它打开父文件夹和第一个子文件夹,它只打印一个 .html 文件。它显示错误:
NO SUCH FILE OR DIRECTORY
我不想更改整个代码。对现有代码的任何修改都对我有好处。
use FileHandle;
opendir PAR_DIR,"D:\\PERL\\perl_programes\\parent_directory";
while (our $sub_folders = readdir(PAR_DIR))
{
next if(-d $sub_folders);
opendir SUB_DIR,"D:\\PERL\\perl_programes\\parent_directory\\$sub_folders";
while(our $file = readdir(SUB_DIR))
{
next if($file !~ m/\.html/i);
print_file_names($file);
}
close(FUNC_MODEL1);
}
close(FUNC_MODEL);
sub print_file_names()
{
my $fh1 = FileHandle->new("D:\\PERL\\perl_programes\\parent_directory\\$file")
or die "ERROR: $!"; #ERROR HERE
print("$file\n");
}