gpt4 book ai didi

c# - 复制文件集时出错

转载 作者:太空宇宙 更新时间:2023-11-03 23:05:39 25 4
gpt4 key购买 nike

我想将一组图像文件从一个路径文件夹复制到另一个文件夹。但是发生了错误:

Illegal characters in path

我试过...

string pathImg = "C" + ":\\compaynameSupportFileImg";

if (!Directory.Exists(pathImg))
{
DirectoryInfo di = Directory.CreateDirectory(pathImg);
di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
string[] jpgFilesNames = Directory.GetFiles(
@"C:\Program Files (x86)\compayname\name", "*.jpg", SearchOption.AllDirectories);

string targetDirectoryImg = pathImg + "\\*.jpg";
foreach (var item in jpgFilesNames)
{
File.Copy(item, targetDirectoryImg, true);
}
}

最佳答案

只需使用:

string pathImg = "C" + ":\\compaynameSupportFileImg";
if (!Directory.Exists(pathImg))
{
DirectoryInfo di = Directory.CreateDirectory(pathImg);
di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
string[] jpgFilesNames = Directory.GetFiles(@"C:\Program Files (x86)\compayname\name", "*.jpg", SearchOption.AllDirectories);
foreach (var item in jpgFilesNames)
{
File.Copy(item, Path.Combine(pathImg, Path.GetFileName(item)), true);
}
}

这里不需要targetDirectoryImg。因为它的值类似于 C:\compaynameSupportFileImg\*.jpg 并且它不是目标文件夹的路径

关于c# - 复制文件集时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41287364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com