【发布时间】:2017-09-06 20:34:44
【问题描述】:
我真的很难过。我是 Perl 的新手,我完全被困在试图遍历所有子目录,执行操作。它在根目录(我的脚本所在的位置)中运行良好,但是一旦它到达子目录,它就会爆炸。我尝试将文件名包含在 " 或 ' 或 q{} 中,但无济于事。我在 StackOverflow 上搜索了这个问题,人们说它应该可以正常工作,打开处理子目录并接受正斜杠。 一旦进入目录并尝试打开“./Horse/Models.meta”,它就在第一次打开(读取文件)时失败。这是在它处理了与我的脚本相同级别的 20 个文件之后。有什么想法吗?
use 5.010;
use strict;
use warnings;
use File::Find;
find(sub {
if (-f and /\.meta$/) {
print "--> " . $File::Find::name . "\n";
open my $in, '<', $File::Find::name or die "Can't read old file: $!";
open my $out, '>', "$File::Find::name.new" or die "Can't write new file: $!";
while( <$in> )
{
if(index($_," assetBundleName:")!=-1) {
print $out " assetBundleName: mobs\n";
} else {
print $out $_;
}
}
close $out;
print("mv -f \"" . $File::Find::name . ".new\" \"" . $File::Find::name . "\"\n");
system("mv -f \"" . $File::Find::name . ".new\" \"" . $File::Find::name . "\"");
}
}, '.');
【问题讨论】:
-
“炸弹”是什么意思?
-
请不要使用"bombs"、"failing"、"doesn't work"等。它根本没有提供有关问题可能是什么的有用信息。
标签: perl file subdirectory