gpt4 book ai didi

perl - 在Perl中将文件复制到尚未创建的目录树中的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-03 12:05:52 25 4
gpt4 key购买 nike

Perl 中将文件复制到尚未创建的目标目录树的最佳方法是什么?

就像是

copy("test.txt","tardir/dest1/dest2/text.txt");

将无法使用,因为目录dirdir / dest1 / dest2还不存在。在Perl中使用目录创建进行复制的最佳方法是什么?

最佳答案

use File::Path;
use File::Copy;

my $path = "tardir/dest1/dest2/";
my $file = "test.txt";

if (! -d $path)
{
my $dirs = eval { mkpath($path) };
die "Failed to create $path: $@\n" unless $dirs;
}

copy($file,$path) or die "Failed to copy $file: $!\n";

关于perl - 在Perl中将文件复制到尚未创建的目录树中的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/229357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com