When I use how DirectoryInfo.EnumerateFiles() it keeps the files open so I can't pass the filename to another process and change the name. How can I get DirectoryInfo.EnumerateFiles() to leave the files closed?
When I use how DirectoryInfo.EnumerateFiles() it keeps the files open so I can't pass the filename to another process and change the name. How can I get DirectoryInfo.EnumerateFiles() to leave the files closed?
Hello @MThomasGroszko-5329 ,
Thanks for your query ! Can you give us more context on this ?
Probably the sample piece of code which you are trying out after enumerating the files - what exactly you want to perform.
I just tried a sample test code after enumerating, I was trying to delete the files etc.
DirectoryInfo di = new DirectoryInfo(@"C:\\test2");
IEnumerable<FileInfo> fi = di.EnumerateFiles();
FileStream fs;
foreach (FileInfo f in fi)
{
Console.WriteLine(f.FullName);
f.Delete();
}
Thanks for looking at this and spending some time. I found my problem.
@MThomasGroszko-5329
We are glad you were able to resolve this! It would be helpful to the community if you could share the resolution and marked this as answered. Have a great day!
5 people are following this question.