Article View: borland.public.cppbuilder.nativeapi
Article #1629Re: Get File Size in Bytes - Silly Question
From: Ed Mulroy [TeamB]
Date: Mon, 09 Jul 2007 14:33
Date: Mon, 09 Jul 2007 14:33
53 lines
2469 bytes
2469 bytes
Corrected version:
See if this does what you want. If it does not find the file or if the file
does not have a size (directories and labels do not report size) then the
returned value is zero.
-------------------------------------
#include <vcl.h>
__int64 __fastcall SizeOfFile(const char *file_name);
inline __int64 SizeOfFile(AnsiString & as)
{
return SizeOfFile(as.c_str());
}
const HANDLE BAD_FIND_VALUE =
reinterpret_cast<HANDLE>(INVALID_HANDLE_VALUE);
__int64 __fastcall SizeOfFile(const char *file_name)
{
WIN32_FIND_DATA wfd;
HANDLE find_hand = ::FindFirstFile(file_name, &wfd);
__int64 result = 0;
if (find_hand != BAD_FIND_VALUE)
{
result = (static_cast<__int64>(wfd.nFileSizeHigh) << 32) |
wfd.nFileSizeLow;
::FindClose(find_hand); // CORRECTION - added
}
return result;
}
-------------------------------------
>
> . Ed
>
>> Robert G. Hoover wrote in message
>> news:46923739@newsgroups.borland.com...
>>
>> I'm sure there's a simple answer to this silly question... my
>> apologies...
>>
>> How can I get the size of a file in bytes given it's absolute filename?
>> I'd
>> rather not open the file and perform a FileSeek to the end to determine
>> the
>> size... I need something quick, no overhead... does such a function
>> exist?
>> Something like GetFileSizeInBytes(Ansistring FileName)?
>
>
Technical Details
Message-ID:
<46924730$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder6.cambrium.nl!feed.tweaknews.nl!xlned.com!feeder1.xlned.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<46923739@newsgroups.borland.com> <46924643$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,82a41b4848349c2f X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <46923739@newsgroups.borland.com> <46924643$1@newsgroups.borland.com> Subject: Re: Get File Size in Bytes - Silly Question Date: Mon, 9 Jul 2007 10:33:16 -0400 Lines: 55 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 NNTP-Posting-Host: 69.142.254.168 Message-ID: <46924730$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1183991600 69.142.254.168 (9 Jul 2007 07:33:20 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder6.cambrium.nl!feed.tweaknews.nl!xlned.com!feeder1.xlned.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail