. NET implements simple incremental file backup programs and. net Incremental Backup
. Net provides many easy-to-use methods, including searching for files in processing files and copying files. Today, Incremental backup files are implemented through simple programs.
First, you need to select the backup source file path SourcePath and the backup target file path DestinationPath, and then use StopWatch to calculate the copy time. (Note: To use StopWatch, you must add the using System. Diagnostics namespace. You must add the using System. IO namespace 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 (); watch. start (); // Start calculation time // check whether the target directory ends with a directory delimiter. if not, add if (DestinationPath [DestinationPath. length-1]! = Path. DirectorySeparatorChar) {DestinationPath + = Path. DirectorySeparatorChar;} // you can create if (! Directory. exists (DestinationPath) {Directory. createDirectory (DestinationPath);} // obtain the file list of the source Directory, which is an array containing files and Directory paths string [] fileList = Directory. getFileSystemEntries (SourcePath); // traverses all files and directories foreach (string SourceFilename in fileList) {string filename = Path. getFileName (SourceFilename); // first, judge whether the object exists in the target folder if (File. exists (DestinationPath + filename) {FileInfo oldFile = new FileInfo (SourceFilename); FileInfo newFile = new FileInfo (DestinationPath + filename); if (oldFile. lastWriteTime = newFile. lastWriteTime) {continue; // jump out of this loop} else {// first as a Directory for processing. if this Directory exists, recursively Copy the files under this Directory if (Directory. exists (SourceFilename) {CopyDirectory (SourceFilename, DestinationPath + filename);} // otherwise, Copy the else {File directly. copy (SourceFilename, DestinationPath + filename, true) ;}} watch. stop (); // time to Stop MessageBox. show ("backup time consumed" + watch. elapsed + ""); // display the time consumed}
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.