Beispiel #1
0
        /// <summary>
        /// Copies a source folder into a target folder accoring to specified options
        /// </summary>
        /// <param name="SrcFolder">The folder that will be copied</param>
        /// <param name="DstFolder">The folder that will receive the copies</param>
        /// <param name="recursive">Whether to deep-copy</param>
        /// <param name="cloneFiles">Whether to copy files</param>
        /// <param name="fileMatch">Criteria filenames must satisfy to be copied</param>
        /// <returns></returns>
        public static IEnumerable <FileCopyResult> Clone(this FolderPath SrcFolder, FolderPath DstFolder,
                                                         bool recursive = true, bool cloneFiles = false, string fileMatch = null)
        {
            DstFolder.CreateIfMissing().Require();
            if (cloneFiles)
            {
                foreach (var x in SrcFolder.CopyFilesTo(DstFolder, fileMatch))
                {
                    yield return(x);
                }
            }

            if (recursive)
            {
                foreach (var srcSubfolder in SrcFolder.Subfolders())
                {
                    foreach (var x in srcSubfolder.Clone(DstFolder + srcSubfolder.FolderName, recursive, cloneFiles, fileMatch))
                    {
                        yield return(x);
                    }
                }
            }
        }