BF2Statistics.DirectoryExt.Copy C# (CSharp) Method

Copy() public static method

Copies the contents of one folder, to another.
public static Copy ( string sourceDirName, string destDirName, bool copySubDirs = true, bool overwriteFiles = false ) : void
sourceDirName string The source folder, being copied
destDirName string The destination dicrectoy, where all the copies will be stored. /// The directory does NOT have to exist.
copySubDirs bool Recursively copy sub folders?
overwriteFiles bool
return void
        public static void Copy(string sourceDirName, string destDirName, bool copySubDirs = true, bool overwriteFiles = false)
        {
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);
            DirectoryInfo[] dirs = dir.GetDirectories();

            // Source directory must exist!
            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + sourceDirName);
            }

            // Create the dir if it doesnt exist
            if (!Directory.Exists(destDirName))
                Directory.CreateDirectory(destDirName);

            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                string temppath = Path.Combine(destDirName, file.Name);
                file.CopyTo(temppath, overwriteFiles);
            }

            // Do we recursivly copy?
            if (copySubDirs)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string temppath = Path.Combine(destDirName, subdir.Name);
                    Copy(subdir.FullName, temppath, copySubDirs, overwriteFiles);
                }
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Restores the ranked python files back to the original state, without affecting
        /// any custom scripts or medal data files
        /// </summary>
        public static void RestoreRankedPyFiles()
        {
            // Use my handy extension method to Copy over the files
            string path = (Installed) ? BF2Server.PythonPath : StatsBackupPath;

            DirectoryExt.Copy(Paths.RankedPythonPath, path, true, true);
        }
All Usage Examples Of BF2Statistics.DirectoryExt::Copy
DirectoryExt