I am trying to copy all PDF files (.pdf) from the source folder to the destination. I have written it using a foreach
loop, but I want to do it without for or any loop. Is there a way to do that, and if so, how?
My Code
string sourcePath = @"D:\DataArchiveTest\From";
string targetPath = @"D:\DataArchiveTest\To";
foreach (var sourceFilePath in Directory.GetFiles(sourcePath))
{
string fileName = Path.GetFileName(sourceFilePath);
string destinationFilePath = Path.Combine(targetPath, fileName);
if (fileName.ToUpper().Contains(".PDF"))
{
System.IO.File.Copy(sourceFilePath, destinationFilePath, true);
}
}