如何在不使用 File::Copy::Recursive 的情况下在 Perl 中复制整个目录?
How can I copy an entire directory in Perl, without using File::Copy::Recursive?
问题:
我的问题与 this one here 几乎相同,只是我不能使用 File::Copy::Recursive。
约束条件:
我无法安装或修改现有环境,所以我坚持使用有效的方法。
use File::Copy; # Works!
use File::Copy::Recursive # Doesn't Work :(
use File::Path # Works!
我收到此错误:(我无法修复此错误,因为我只是该系统的用户,不是管理员或任何其他用户)
Can't locate File/Copy/Recursive.pm in @INC (@INC contains: /path/to/some/place /path/to/other/place .) at my_program.pl line 13.
场景:
如果有帮助,我的方案是我想复制内容目录,假设 ~/my_dir
到此处 ~/
已经存在的目录。 ~/my_dir
有一个子文件夹 ~/my_dir/sub_dir
,我想复制该目录及其所有内容。
无论如何,系统的工具在这方面要好得多。
system('cp', '-rp', '--', $src, $dst);
die("Can't launch cp: $!\n") if $? == -1;
die("cp killed by signal ".($? & 0x7F)."\n") if $? & 0x7F;
die("cp exited with error ".($? >> 8)."\n") if $? >> 8;
缺点是缺乏便携性。如果您想要可移植性,请安装 File::Copy::Recursive。如果你可以在一台机器上安装你的脚本,你也可以安装 File::Copy::Recursive.
问题:
我的问题与 this one here 几乎相同,只是我不能使用 File::Copy::Recursive。
约束条件:
我无法安装或修改现有环境,所以我坚持使用有效的方法。
use File::Copy; # Works!
use File::Copy::Recursive # Doesn't Work :(
use File::Path # Works!
我收到此错误:(我无法修复此错误,因为我只是该系统的用户,不是管理员或任何其他用户)
Can't locate File/Copy/Recursive.pm in @INC (@INC contains: /path/to/some/place /path/to/other/place .) at my_program.pl line 13.
场景:
如果有帮助,我的方案是我想复制内容目录,假设 ~/my_dir
到此处 ~/
已经存在的目录。 ~/my_dir
有一个子文件夹 ~/my_dir/sub_dir
,我想复制该目录及其所有内容。
无论如何,系统的工具在这方面要好得多。
system('cp', '-rp', '--', $src, $dst);
die("Can't launch cp: $!\n") if $? == -1;
die("cp killed by signal ".($? & 0x7F)."\n") if $? & 0x7F;
die("cp exited with error ".($? >> 8)."\n") if $? >> 8;
缺点是缺乏便携性。如果您想要可移植性,请安装 File::Copy::Recursive。如果你可以在一台机器上安装你的脚本,你也可以安装 File::Copy::Recursive.