public static void CopyDirectory( DirectoryInfo src, DirectoryInfo target, bool withHiddenFiles = true, bool withHiddenFolders = true, Func<FileInfo, bool> fileFilter = null, Func<DirectoryInfo, bool> dirFilter = null )
{
if( src == null ) throw new ArgumentNullException( "src" );
if( target == null ) throw new ArgumentNullException( "target" );
if( !target.Exists ) target.Create();
DirectoryInfo[] dirs = src.GetDirectories();
foreach( DirectoryInfo d in dirs )
{
if( (withHiddenFolders || ((d.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden))
&& (dirFilter == null || dirFilter( d )) )
{
CopyDirectory( d, new DirectoryInfo( Path.Combine( target.FullName, d.Name ) ), withHiddenFiles, withHiddenFolders );
}
}
FileInfo[] files = src.GetFiles();
foreach( FileInfo f in files )
{
if( (withHiddenFiles || ((f.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden))
&& (fileFilter == null || fileFilter( f )) )
{
f.CopyTo( Path.Combine( target.FullName, f.Name ) );
}
}
}