private void doFileWork() { List <filePair> fileList = new List <filePair>(); if (firstRun) { firstRun = false; foreach (DataGridViewRow dr in dataGridView1.Rows) { string source = dr.Cells[1].Value.ToString(); string destination = dr.Cells[2].Value.ToString(); string filter = dr.Cells[3].Value.ToString(); Console.WriteLine("Source: " + source); Console.WriteLine("Destination: " + destination); Console.WriteLine("Filter: " + filter); //DriveInfo di = new System.IO.DriveInfo(@source); DirectoryInfo dirInfo = new DirectoryInfo(source); Console.WriteLine(dirInfo.Attributes.ToString()); // Get the files in the directory and print out some information about them. System.IO.FileInfo[] fileNames = dirInfo.GetFiles(filter); // THIS IS A METHOD FOR SEARCHING MULTIPLE FILES BUT I HAVE DECIDED TO USE THE PREVIOUS ONE AND DO ONE EXTENSION AT A TIME // var files = Directory.EnumerateFiles(source, "*.*", SearchOption.AllDirectories) // .Where(s => s.EndsWith(".mp4") || s.EndsWith(".MOV") || s.EndsWith(".wmv")); foreach (FileInfo fi in fileNames) { filePair fp = new filePair(); fp.source = fi; fp.destination = destination; fileList.Add(fp); } } if (fileList.Count > 0) { workingOnChanges = true; // MoveTime(); progresslabel.Visible = true; copyProgressBar.Visible = true; moveFile MF = new moveFile(); MF.fileList = fileList; // Start the asynchronous operation. backgroundWorker1.RunWorkerAsync(MF); lastFile = ""; } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // This event handler is where the actual work is done. // This method runs on the background thread. // Get the BackgroundWorker object that raised this event. System.ComponentModel.BackgroundWorker worker; worker = (System.ComponentModel.BackgroundWorker)sender; // Get the Words object and call the main method. moveFile MF = (moveFile)e.Argument; MF.moveF(worker, e); }