C # File handling (copy from one folder to another folder)

Source: Internet
Author: User
Tags file handling

We often encounter problems such as copying and uploading files. Especially in automatic production, the files thrown by the machine need to be transported, collected, and then analyzed in the data, and so on.

WinForm, the collection of more common file handling.

1      Private voidMoveFile ()2         {3             stringFrompath =@"D:\Test\OutPut";4             stringDirectoryPath =@"D:\report";5             Try6             {7                 string[] piclist = Directory.GetFiles (Frompath,"*.jpg");//Image8                 string[] txtlist = Directory.GetFiles (Frompath,"*.txt");//text File9                 string[] pdflist = Directory.GetFiles (Frompath,"*.pdf");//PDF FileTen     One                 foreach(stringFinchpiclist) A                 { -                     //gets the file name. -                     stringFName = f.substring (Frompath.length +1); theFile.Copy (Path.Combine (Frompath, FName), Path.Combine (DirectoryPath, FName),true); -                 } -                 foreach(stringFinchtxtlist) -                 { +                     stringFName = f.substring (Frompath.length +1); -                     Try +                     { A file.copy (Path.Combine (Frompath, FName), Path.Combine (DirectoryPath, FName)); at                     } -                     //catches an exception. -                     Catch(IOException copyerror) -                     { - MessageBox.Show (copyerror.message); -                     } in                 } -                 foreach(stringFinchpdflist) to                 { +                     stringFName = f.substring (Frompath.length +1); -                     Try the                     { * file.copy (System.IO.Path.Combine (Frompath, FName), System.IO.Path.Combine (DirectoryPath, FName )); $                     }Panax Notoginseng                     Catch(IOException copyerror) -                     { the MessageBox.Show (copyerror.message); +                         return; A                     } the                 }               +                 //Delete files in the original folder -                 foreach(stringFinchtxtlist) $                 { $ File.delete (f); -                 } -                 foreach(stringFinchpiclist) the                 { - File.delete (f);Wuyi                 } the                 foreach(stringFinchpdflist) -                 { Wu File.delete (f); -                 } About  $             } -             Catch(directorynotfoundexception dirnotfound) -             { - MessageBox.Show (dirnotfound.message); A             } +}

C # File handling (copy from one folder to another folder)

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.