就像是
copy("test.txt","tardir/dest1/dest2/text.txt");
由于目录tardir / 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";