🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1627

Re: Get File Size in Bytes - Silly Question

#1627
From: Jonathan Benedicto
Date: Mon, 09 Jul 2007 14:25
32 lines
2031 bytes
Robert G. Hoover wrote:
> 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)?

If you are ok with Win98 and higher, you could use the GetFileAttributesEx 
function. Eg:

WIN32_FILE_ATTRIBUTE_DATA FileAttr;

if( GetFileAttributesEx( FileName, GetFileExInfoStandard, &FileAttr ) )
{
    LARGE_INTEGER li;
    li.LowPart = FileAttr.nFileSizeLow;
    li.HighPart = FileAttr.nFileSizeHigh;

    unsigned __int64 FileSizeInBytes = li.QuadPart;


}

Otherwise you'll have to open the file with CreateFile, then use GetFileSize 
on the handle.

HTH

Jon 
Technical Details
Message-ID: <46924577$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-mail
References: <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: "Jonathan Benedicto" <invalid@nobody.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <46923739@newsgroups.borland.com>
In-Reply-To: <46923739@newsgroups.borland.com>
Subject: Re: Get File Size in Bytes - Silly Question
Date: Mon, 9 Jul 2007 10:25:55 -0400
Lines: 33
MIME-Version: 1.0
Content-Type: text/plain;
 format=flowed;
 charset="iso-8859-1";
 reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Windows Mail 6.0.6000.16480
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16480
NNTP-Posting-Host: 74.115.18.89
Message-ID: <46924577$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1183991159 74.115.18.89 (9 Jul 2007 07:25:59 -0700)
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