Article View: borland.public.cppbuilder.nativeapi
Article #1630Re: Get File Size in Bytes - Silly Question
From: Ed Mulroy [TeamB]
Date: Mon, 09 Jul 2007 14:29
Date: Mon, 09 Jul 2007 14:29
46 lines
2337 bytes
2337 bytes
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;
}
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:
<46924643$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.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>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> Subject: Re: Get File Size in Bytes - Silly Question Date: Mon, 9 Jul 2007 10:29:19 -0400 Lines: 48 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 NNTP-Posting-Host: 69.142.254.168 Message-ID: <46924643$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1183991363 69.142.254.168 (9 Jul 2007 07:29:23 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail