Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File.Delete() versus FileInfo.Delete()

Is there much of a difference between using the static methods of the File object as opposed to creating a new FileInfo object and calling those methods?

like image 967
Tim Coker Avatar asked Oct 14 '11 20:10

Tim Coker


3 Answers

The only difference is that File must resolve the specified path (assuming it is relative), while the FileInfo should have already have the resolved path.

like image 51
CodeNaked Avatar answered Sep 23 '22 05:09

CodeNaked


Both are calling Win32Native.DeleteFile()

like image 30
Ilia G Avatar answered Sep 23 '22 05:09

Ilia G


It depends. If you are performing a single operation use the File class and if you are performing multiple operations on the same file, use FileInfo.

EDIT: I made this point as my understanding is that the File class's static methods will always check for the security. But if you are re-using the instance of FileInfo, the methods will do the security check only for the first time and not on each subsequent calls.

like image 27
Jesse Avatar answered Sep 23 '22 05:09

Jesse