CK.Core.FileUtil.CopyDirectory C# (CSharp) Method

CopyDirectory() public static method

Recursively copy a directory, creates it if it does not already exists. Throws an IOException, if a same file exists in the target directory.
public static CopyDirectory ( DirectoryInfo src, DirectoryInfo target, bool withHiddenFiles = true, bool withHiddenFolders = true, bool>.Func fileFilter = null, bool>.Func dirFilter = null ) : void
src System.IO.DirectoryInfo The source directory.
target System.IO.DirectoryInfo The target directory.
withHiddenFiles bool False to skip hidden files.
withHiddenFolders bool False to skip hidden folders.
fileFilter bool>.Func Optional predicate for directories.
dirFilter bool>.Func Optional predicate for files.
return void
        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 ) );
                }
            }
        }