Esempio n. 1
0
        /// <summary>
        /// Copy additional folders and files.
        /// </summary>
        /// <param name="copyFrom">Copy from directory.</param>
        /// <param name="searchPattern">
        /// Search pattern.
        /// See more at https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getdirectories?view=net-5.0#System_IO_Directory_GetDirectories_System_String_System_String_System_IO_SearchOption_
        /// </param>
        /// <param name="copyTo">Copy to directory.</param>
        public int CopyAdditional(string copyFrom, string searchPattern, string copyTo)
        {
            int          copyCount    = 0;
            ConsoleStyle ConsoleStyle = new ConsoleStyle(this.MPHPSwitchConfig);

            if (Directory.Exists(copyFrom))
            {
                // create folders on target.
                foreach (string dirPath in Directory.GetDirectories(copyFrom, searchPattern, SearchOption.AllDirectories))
                {
                    string relDirPath  = dirPath.Replace(copyFrom, "");
                    char[] charsToTrim = { ' ', '"', '\'', '/', '\\' };
                    relDirPath = relDirPath.Trim(charsToTrim);
                    Directory.CreateDirectory(NormalizePath(copyTo) + Path.DirectorySeparatorChar + relDirPath);
                    ConsoleStyle.WriteVerbose("      --{0}", NormalizePath(copyTo) + Path.DirectorySeparatorChar + relDirPath);
                    copyCount++;
                }

                // copy all files to target.
                foreach (string filePath in Directory.GetFiles(copyFrom, searchPattern, SearchOption.AllDirectories))
                {
                    string relFilePath = filePath.Replace(copyFrom, "");
                    char[] charsToTrim = { ' ', '"', '\'', '/', '\\' };
                    relFilePath = relFilePath.Trim(charsToTrim);
                    File.Copy(filePath, NormalizePath(copyTo) + Path.DirectorySeparatorChar + relFilePath, false);
                    ConsoleStyle.WriteVerbose("      --Copied {0}", NormalizePath(copyTo) + Path.DirectorySeparatorChar + relFilePath);
                    copyCount++;
                }
            }

            return(copyCount);
        }