简体   繁体   中英

how to copy multiple files from one directory to another with progressBar in c# window form

I'm going to copy multiple files from one directory to another but the problem i face is that "my code copy only one file from one directory to another" .

actually i'm going to make the clone of File explorer with specified directory . I've tried to copy multiple files from one directory to another but my code work on only coping one file from multiple files.

OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK){ 
 string dess = path_textBox.Text;
 File.Copy(ofd.FileName, dess + "\\" + ofd.SafeFileName, true);}

I expect the output is "Coping multiple files from one directory to another in c# window form"

Copy Multiple Files

string strDestinationFolder = @"D:\Barcode Copied";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK) 
{
   foreach (string fileName in ofd.FileNames)
   {
      System.IO.File.Copy(fileName, strDestinationFolder + @"\" + System.IO.Path.GetFileName(fileName));
    }
 }
  1. Get all files and put it to list
  2. Put it to for loop
  3. Update progress using loop index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM