Is it possible to get the size of a file in C# without using System.IO.FileInfo
at all?
I know that you can get other things like Name and Extension by using Path.GetFileName(yourFilePath)
and Path.GetExtension(yourFilePath)
respectively, but apparently not file size? Is there another way I can get file size without using System.IO.FileInfo
?
The only reason for this is that, if I'm correct, FileInfo grabs more info than I really need, therefore it takes longer to gather all those FileInfo's if the only thing I need is the size of the file. Is there a faster way?
FileInfo
, profile the code, and determine if it is fast enough for your needs. If you have verified that it is both a substantial percentage of the runtime of your application, and that your application is unacceptably slow, then consider other options. – SnowbirdFileInfo
is generally 15% overhead without optimization X, I believe that is what they are after. – LepineFileInfo
, because it is not an answer to the question, just the likely course of action the OP should take anyway. – SnowbirdSystem.IO.FileInfo
uses Win32'sFindFirstFile
API call to extract aWIN32_FIND_FILE
structure. You could useGetFileSizeEx
but it requires aHANDLE
which you must obtain from opening the file first. I would assume the former is better on performance. If you really need insane performance, then try the Win32 calls toFindFirstFile
(andFindClose
) yourself. – Investigation