. Net-based incremental file backup system implementation and. net Incremental Backup implementation

Source: Internet
Author: User

. Net-based incremental file backup system implementation and. net Incremental Backup implementation

. 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; // jumps out of this loop }}
Else {// first as a Directory. 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 Stop
MessageBox. Show ("backup completion time" + watch. Elapsed + ""); // display consumed time}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.