CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002
    Location
    Hamburg / Germany
    Posts
    280

    Retrieve whole folder-size

    Hi,
    I read a lot of text on several websites, of course Codeguru too about retrieving the size of a directory with all files and subdirs summarized.

    All I found described the solution as recursively parse the dirs using FindFirstFile, FindNextFile etc.

    Ok, that is what I did first too, and I have a class named DirectoryWalker that does that job (among others) very well.

    Anyway, I allways asked myself if there is any easier way to get the size of a Dir. Iheard rumors about some weird shell-fuctions working with shell-objects, and I remember through the mist of time that somebody told me there is a way to use them to do my task. now I read through MSDN and couldn't find anything about my problem and a solution using shell-functions.

    So I ask you: Do you know such a magic way like calling a function GetDirSize() or so from Win32API ?

    Somebody told me, that Win-Explorer also retrieves dirsize recursing the directory when showing properties. Maybe my code is inefficient, because my recursing and summarizing routine takes much more time to retrieve the size of a dir as the explorer takes. I optimized the dirwalk over and over, but it stays rather slow. I found one part of my code that might cause the slowdown, but cannot find a way to optimize that. It is for getting the REAL occupation of diskspace for a file including clustering.

    I have one unsigned int called clustersize for the size of one cluster initialized. also I have a int64 called filesize for the actual physical filesize. the algorythm is performed for EACH file found in the dir and its subdirs and looks like this:

    int r = filesize % clustersize;

    if (r > 0)
    {
    filesize -= r;
    filesize += clustersize
    }

    That's all, any suggestions ?

    Since my application in progress is a diskspace-monitoring-tool the operation of retrieving the whole size of a folder is relative often used, which makes it VERY neccessary to get this work done quick.

    I would appreciate any help.

    thanx in advance

    Juergen

  2. #2
    Join Date
    Sep 2002
    Location
    The Great India
    Posts
    51
    No Win32 API such,

    But you have FileSystemObject , you can create an instance of Com object , Scripting.FileSystemObject and it has facility to get folder and its size without doing any recursive stuff.

    See VB Script documentation to know more about FileSystemObject

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured