Is it safe to delete or move files or directories when using Directory.EnumerateFiles
?
Something like this:
foreach (var fileName in Directory.EnumerateFiles("Sub"))
File.Delete(fileName);
I know that, in general, you are not supposed to modify what you're enumerating. However, the file system doesn't seem to be following that rule since the code above works.
The same question applies to EnumerateDirectories
and EnumerateFileSystemEntries
, as well as the equivalent methods of the DirectoryInfo
class.