How do I copy a directory including sub directories excluding files or directories that match a certain regex on a Windows system?
相关问题
- PHP Recursively File Folder Scan Sorted by Modific
- $ENV{$variable} in perl
- How to access the camera from my Windows Phone 8 a
- Is it possible to pass command-line arguments to @
- Redirecting STDOUT and STDERR to a file, except fo
相关文章
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Recursively replace keys in an array
- Python: Maximum recursion depth exceeded when prin
- Is recursion good in SQL Server?
- Can NOT List directory including space using Perl
- How does this list comprehension over the inits of
- Extracting columns from text file using Perl one-l
If you happen to be on a Unix-like OS and have access to
rsync (1)
, you should use that (for example throughsystem()
).Perl's File::Copy is a bit broken (it doesn't copy permissions on Unix systems, for example), so if you don't want to use your system tools, look at CPAN. Maybe File::Copy::Recursive could be of use, but I don't see any exclude options. I hope somebody else has a better idea.
I'd do something like this:
I don't know how to do an exclusion with a copy, but you could work something up along the lines of:
Another option is File::Xcopy. As the name says, it more-or-less emulates the windows xcopy command, including its filtering and recursive options.
From the documentation:
A classic answer would use '
cpio -p
':The '
cpio
' command deals with the actual copying, including permission preservation. The trick of 'cd $SOURCE_DIR; find . ...
' deals with removing the leading part of the source path from the names. The only problem with that invocation of 'find
' is that it won't follow symlinks; you need to add '-follow
' if that's what you want.