简体   繁体   English

如何使用c#窗口形式的progressBar将多个文件从一个目录复制到另一个目录

[英]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 . 实际上,我将使用指定目录克隆File Explorer。 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" 我希望输出为“以c#窗口形式将多个文件从一个目录复制到另一个目录”

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 使用循环索引更新进度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将文件从一个目录复制到另一目录? - How do i copy files from one directory to another directory? 使用C#中的cmd将文件从一个目录复制到另一个目录 - Copy file from one directory to another using cmd in C# C#:如何仅将文件中的差异从一个目录复制到另一个目录 - C#: How to copy only the differences in a file from one directory to another 如何使用C#中的WinSCP .NET程序集将内容从一个远程目录复制到同一服务器中的另一个目录 - How to copy things from one remote directory to another in the same server using WinSCP .NET assembly in C# C#将文件从一个文件夹复制到另一个文件夹而不重复 - C# to copy files from one folder to another without duplicates 使用c#可靠地将文件从一台服务器复制到另一台 - Reliably copy files from one server to another using c# 如何使用C#将数据从Form复制到另一个Form? - how to copy data from Form to another Form using C#? 如何将目录和文件从一个外部复制到另一个 C# 控制台 - How to copy directories and files from one external to another C# Console 如何在 C# 中多次将内容从一个数据表复制到另一个数据表 - How to Copy contents from one datatable to another datatable multiple times in C# 如何在C#中将多个记录从一种形式传递到另一种形式? - How can I pass multiple records from one form to another form in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM