views:

34

answers:

1

In our application, we are generating some large ASCII log files to an Windows NTFS compressed directory. My users want to know both the compressed and uncompressed size of the files on a status screen for the application. We are using Rad Studio 2010 C++ for this application.

I found this nice recursive routine online to read the size of the files on the disk -

__int64 TransverseDirectory(string path)
{
    WIN32_FIND_DATA data;
    __int64 size  = 0;
    string  fname = path + "\\*.*";
    HANDLE  h     = FindFirstFile(fname.c_str(), &data);

    if (h != INVALID_HANDLE_VALUE)
    {
        do
        {
            if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
            {
                if (strcmp(data.cFileName, ".") != 0 && strcmp(data.cFileName, "..") != 0)
                {
                    // We found a sub-directory, so get the files in it too
                    fname = path + "\\" + data.cFileName;
                    // recurrsion here!
                    size += TransverseDirectory(fname);
                }
            }
            else
            {
                LARGE_INTEGER sz;
                sz.LowPart  = data.nFileSizeLow;
                sz.HighPart = data.nFileSizeHigh;
                size       += sz.QuadPart;
                // ---------- EDIT ------------ 
                if (data.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)
                     {
                       unsigned long doNotCare;
                        fname = path + "\\" + data.cFileName;
                        DWORD lowWordCompressed = GetCompressedFileSize(fname.c_str(),
                        &doNotCare);
                        compressedSize += lowWordCompressed;
                      }
                // ---------- End EDIT ------------ 
            }
        }
        while (FindNextFile(h, &data) != 0);
        FindClose(h);
    }
    return size;
}

But what I cannot find is any information on how to read compressed/uncompressed file size information. Suggestions on where to look?

+5  A: 

The Win32 API GetFileSize will return the uncompressed file size. The API GetCompressedFileSize will return the compressed file size.

Mark