Reputation: 341
I want to copy set of image files from one path folder to another folder. But error occurred:
Illegal characters in path
I have tried...
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);
}
}
Upvotes: 1
Views: 114
Reputation: 24619
Just use:
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);
}
}
You do not need targetDirectoryImg
here. Because it will has value like C:\compaynameSupportFileImg\*.jpg
and it isn't path to target folder
Upvotes: 3