.Net provides many convenient methods, including finding files in processing files, copying files, etc. Today, what is implemented is to implement incremental backup files through simple programs.
The first thing you need is to select the backup source file path SourcePath and the backup target file path DestinationPath, and then count the time it takes to copy through StopWatch. (Note: Using namespace is required to add using namespace to use when using StopWatch, and using namespace is required to read and write files).
/// <summary> /// Incremental backup function method/// </summary> /// <param name="SourcePath">Backup source file path</param>/// <param name="DestinationPath">Backup target file path</param>public void CopyDirectory(String SourcePath, String DestinationPath){ Stopwatch watch = new Stopwatch(); (); //Start calculation time // Check whether the target directory ends with directory segmentation characters. If not, add if (DestinationPath[ - 1] != ) { DestinationPath += ; } //Judge whether the target directory exists or not, create a new one. if (!( DestinationPath)) { (DestinationPath); } // Get the file list of the source directory, which is an array containing the file and directory paths string[] fileList = (SourcePath); // traverse all files and directories foreach (string SourceFilename in fileList) { string filename = (SourceFilename); //First determine whether the file exists in the target folder if ((DestinationPath + filename)) { FileInfo oldFile = new FileInfo(SourceFilename); FileInfo newFile = new FileInfo(DestinationPath + filename); if ( == ) { continue; //Breaking out of this loop } } else { // First treat it as a directory. If this directory exists, recursively copy the files below the directory. if ((SourceFilename)) { CopyDirectory(SourceFilename, DestinationPath + filename); }// Otherwise, directly copy the file else { (SourceFilename, DestinationPath + filename, true); } } } (); //Time stop ("Backup completes time consumed"++""); //Show the time consumed}
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.