开发者

How can I copy a directory but ignore some files in Perl?

In my Perl code, I need to copy a directory from one location to another on the same host excluding some files/patterns (e.g. *.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开发者_C百科 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


I'd use File::Find, and step over each file, but instead of calling File::Copy's copy() on each file, first test to see if it matches the pattern, and then next if it does.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜