KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I used this code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using System.IO; namespace WindowsApplication1 { public partial class Form1 : Form { // Class to report progress private class UIProgress { public UIProgress(string name_, long bytes_, long maxbytes_) { name = name_; bytes = bytes_; maxbytes = maxbytes_; } public string name; public long bytes; public long maxbytes; } // Class to report exception { private class UIError { public UIError(Exception ex, string path_) { msg = ex.Message; path = path_; result = DialogResult.Cancel; } public string msg; public string path; public DialogResult result; } private BackgroundWorker mCopier; private delegate void ProgressChanged(UIProgress info); private delegate void CopyError(UIError err); private ProgressChanged OnChange; private CopyError OnError; public Form1() { InitializeComponent(); mCopier = new BackgroundWorker(); mCopier.DoWork += Copier_DoWork; mCopier.RunWorkerCompleted += Copier_RunWorkerCompleted; mCopier.WorkerSupportsCancellation = true; OnChange += Copier_ProgressChanged; OnError += Copier_Error; button1.Click += button1_Click; ChangeUI(false); } private void Copier_DoWork(object sender, DoWorkEventArgs e) { // Create list of files to copy string[] theExtensions = { "*.jpg", "*.jpeg", "*.bmp", "*.png", "*.gif" }; List<FileInfo> files = new List<FileInfo>(); string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); DirectoryInfo dir = new DirectoryInfo(path); long maxbytes = 0; foreach (string ext in theExtensions) { FileInfo[] folder = dir.GetFiles(ext, SearchOption.AllDirectories); foreach (FileInfo file in folder) { if ((file.Attr
Tags (comma-separated)
Save Edits
Cancel