我要将多个文件从一个目录复制到另一个目录,但我面临的问题是“我的代码只将一个文件从一个目录复制到另一个目录”。
实际上,我将使用指定的目录进行File explorer的克隆。我试图将多个文件从一个目录复制到另一个目录,但我的代码只处理来自多个文件的一个文件。
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);}
我希望输出是“以c#窗口形式将多个文件从一个目录复制到另一个目录”
复制多个文件
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));
}
}