0
File::Find::find ( sub {
    #
    unlink if int -M $File::Find::name > 100;
    File::Copy::move $File::Find::name, "/$File::Find::dir/backup" if $File::Find::name =~ /ERROR/;
    }, $dir );

在 File::Find::find 中移动和删除文件是否安全?

4

2 回答 2

4

删除:是的。wantedFile::Find 在调用目录中的任何文件之前读取整个目录。

移动:不,因为您要将文件移动到您可能访问的目录中。但是,如果您添加了以下所需的代码段,那将是安全的。

if ($_ eq 'backup') {
   $File::Find::prune = 1;
   return;
}

此外,之后您确实应该拥有以下内容:

return if !-f $_;
于 2013-01-31T09:05:18.530 回答
0

Should be fine moving and deleting files. If you are moving and deleting the directories as you are working on them it might get somewhat confusing. The list of files and directories will be made at the start of the sub so new files and directories that you make during the sub running will not be considered

Hope this helps

于 2013-01-31T09:00:44.933 回答