In my Perl code, I need to copy a directory from one location to another on the same host excluding some files/patterns (eg *.log, ./myDir/abc.cl). What would be the optimum way of doing this in Perl across all the platforms? On Windows, xcopy is one such solution. On unix platforms, is there a way to do this in Perl?
I think you're looking for rsync . It's not Perl, but it's going to work a lot better than anything you make in Perl:
% rsync --exclude='*.log' --exclude='./myDir/abc.cl' SOURCE DEST
If you have a bunch of patterns, you can put those all in a file:
*.log
./myDir/abc.cl
Now ignore all the patterns in a file:
% rsync --exclude-from=do_not_sync.txt SOURCE DEST
我会使用File::Find
,并一步在每个文件,但不是调用File::Copy
的copy()
上的每个文件,最先看到的测试,如果它的模式匹配,然后next
,如果它。
On *nix, you can use native tar command, with -exclude options . Then after creating the tar file, you can bring it over to your destination to untar it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.