question

MThomasGroszko-5329 avatar image
0 Votes"
MThomasGroszko-5329 asked deherman-MSFT commented

How to get DirectoryInfo.EnumerateFiles() to close files?

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?

azure-files
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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();

         }
1 Vote 1 ·

Thanks for looking at this and spending some time. I found my problem.

0 Votes 0 ·
deherman-MSFT avatar image deherman-MSFT MThomasGroszko-5329 ·

@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!

0 Votes 0 ·

0 Answers