-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.IOenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions
Milestone
Description
FileInfo.Delete() does not update .Exists
So I just noticed:
// this file exists
var fi = new FileInfo(@"S:\Ome\File.path");
// here fi.Exists == true
fi.Delete();
// still fi.Exists == true
fi.Refresh();
// finally fi.Exists == falseThe code I wrote assumed Delete() changes .Exists and it was failing very unexpectedly. Checked the actual source code and found Delete() is implemented as:
public override void Delete() => FileSystem.DeleteFile(FullPath);instead of:
public override void Delete()
{
FileSystem.DeleteFile(FullPath);
Invalidate();
}Why is this simple operation not updating .Exists if it succeeds? On the other hand MoveTo() changes the fi object completely updating to the new path. So if you do a Delete() you need to followup with a Refresh() while a MoveTo() is good (even if it would have been better if Move() returned a new FileInfo with the new details instead of changing the current one).
Is this inconsistency by design or was it just overlooked?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.IOenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions