Search code examples
c#winformsmulti-selectopenfiledialogfile-copying

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"


Solution

  • 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));
        }
     }