0)~/test/perl$ cat pathcp.pl #!/usr/bin/perl use strict; use File::Basename; use File::Path; use File::Spec::Functions; use File::Copy; sub xcp { my ($dest_dir, $src_file, $keep_path) = @ARGV; my $raw_file = substr($src_file, length($keep_path)); my $base = basename($raw_file); my $dir = dirname($raw_file); $dest_dir = catfile($dest_dir, $dir); eval{mkpath($dest_dir) unless (-d $dest_dir)} || die "failed to mkpath [$dest_dir]"; copy($src_file, $dest_dir) || die "failed to copy file [$src_file]"; } xcp @ARGV; __END__ perl pathcp.pl m/n/o/p a/b/c/d/e/f.txt a/b/ xcp m/n/o/p a/b/c/d/e/f.txt a/b/
xiaoqing找我说,怎么能复制的时候带部分路径。复制,路径,部分,三个关键词。关于File这一族的模块,好久不用了,很是生疏。