|
-
September 17th, 2004, 08:08 AM
#1
Get File Size
Hi
What is the fastest way to retrieve the (64 bit) filesize of a file?
I need to get the size of *many* files from various locations (on WinXP systems,only), so what would be faster:
CreateFile + GetFileSize + CloseHandle
or
FindFirstFile / FindNextFile
or do you have another idea?
Thank you in advance.
Oliver.
-
September 17th, 2004, 09:02 AM
#2
Re: Get File Size
hi,
FindFirstFile/FindNextFile/FindClose seems to be the fastest and
preferred ...IMHO
Praseed Pai
-
September 17th, 2004, 09:28 AM
#3
Re: Get File Size
Although I haven't used any of them so far, but they look handy for this purpose.
GetFileSize
GetCompressedFileSize
GetFileSizeEx
-
September 17th, 2004, 09:40 AM
#4
Re: Get File Size
You can also try GetFileAttributesEx ().
I'm not sure whether it is faster than FindFirst/FindNext/FindClose, but it is definitely faster than CreateFile/GetFileSize (which also modifies the file last access time).
-
September 17th, 2004, 01:09 PM
#5
Re: Get File Size
Thank you for your suggestions!
@Ejaz
But GetFileSize etc. require that the file was previously opened by a call to CreateFile. This is the API I'm currently using, but it seems a little slow to me.
@genossa
Bingo! I knew there was a function which takes the file path and returns the 64bit file size, but I could not remember what it was. I believe this will be much faster, so I'll try it next week and post the results of my little test 
Thank you all & have a good weekend.
Oliver.
-
September 18th, 2004, 01:53 PM
#6
Re: Get File Size
I use _stat64 which accepts a filename and which retrieves a 64 bit size.
-
September 20th, 2004, 04:57 AM
#7
Re: Get File Size
I just tried GetFileAttributesEx(...) and it really seems to be *much* faster than GetFileSize(...)!
The only drawback is that GetFileAttributesEx(...) is not supported by Win95.
@Marc G
Thank you; I didn't knew this C runtime function (_stati64, _wstati64). I'll give them a try and report back!
Oliver.
-
September 21st, 2004, 05:33 AM
#8
Re: Get File Size
 Originally Posted by Marc G
I use _stat64 which accepts a filename and which retrieves a 64 bit size.
At least on my Win2k workstation, _stati64 is screaming fast compared to CreateFile / GetFileSize / CloseFile!
Maybe it is a drawback that it does not support security attributes, but I do not need that anyway.
Thank you for this tip!
Oliver.
-
September 21st, 2004, 08:46 AM
#9
Re: Get File Size
One more tip:
_stat64 uses FindFirstFile/FindClose inside (just looked into the source code of
_stat64 for Visual Studio). So, if your application is designed for Windows paltform then using FindFirstFile/FindClose directly will be a little bit faster than calling to _stat64
-
September 22nd, 2004, 03:42 AM
#10
Re: Get File Size
Hi genossa
Where did you look it up? I just searched the MS VC directory and the web but did not find the implementation of stati64.
BTW: The function names are _stati64 and _wstati64().
Oliver.
-
September 22nd, 2004, 03:48 AM
#11
Re: Get File Size
Oh, I just found it: VC98\CRT\SRC\STAT.C function declaration "int __cdecl _tstati64".
It really uses FindFirstFile / FindClose API. I must say that I did not believe these APIs are that fast!
Thank you.
Oliver.
-
September 22nd, 2004, 03:51 AM
#12
Re: Get File Size
Hi ,
on my machine i have installed VS.net in the C folder.
u may find the source code of the routines mentioned above in the following path
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\crt\src
Praseed Pai
www.praseedpai.com
-
September 22nd, 2004, 05:42 AM
#13
Re: Get File Size
BTW: The function names are _stati64 and _wstati64().
Oops. My bad.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|