Article View: borland.public.cppbuilder.nativeapi
Article #9503Re: file size
From: Remy Lebeau (TeamB)
Date: Tue, 06 Jul 2004 08:42
Date: Tue, 06 Jul 2004 08:42
44 lines
2311 bytes
2311 bytes
"Berlani" <jc.berlani@vacotec.ch> wrote in message
news:40ea5b75@newsgroups.borland.com...
> What is the way to obtain the size of all files from
> one directory (include the sub-folder) ?
Call FindFirstFile() and FindNextFile() recursively. They return a
WIN32_FIND_DATA structure which contains (amongst other things) the file
size for each individual file found. You can then tally the file sizes
together to get the total size of the folder and subfolders. For example:
unsigned __int64 __fastcall GetFolderSize(const AnsiString &Folder)
{
WIN32_FIND_DATA fd = {0};
unsigned __int64 result = 0;
AnsiString asFolder = IncludeTrailingBackslash(Folder);
AnsiString asMask = asFolder + "*.*";
HANDLE hFindFile = ::FindFirstFile(asMask.c_str(), &fd);
if( hFindFile != INVALID_HANDLE_VALUE )
{
do
{
if( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
result += GetFolderSize(asFolder + fd.cFileName);
else
{
ULARGE_INTEGER ul;
ul.HighPart = fd.nFileSizeHigh;
ul.LowPart = fd.nFileSizeLow;
result += ul.QuadPart;
}
}
while( ::FindNextFile(hFindFile, &fd) );
::FindClose(hFindFile);
}
return result;
}
Gambit
Technical Details
Message-ID:
<40ea65df$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40ea5b75@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7d7ca404f173d9c2 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40ea5b75@newsgroups.borland.com> Subject: Re: file size Date: Tue, 6 Jul 2004 01:42:27 -0700 Lines: 46 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.10 Message-ID: <40ea65df$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1089103327 68.69.17.10 (6 Jul 2004 01:42:07 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail