Sunday, 25 January 2015

Calculate Size of a folder in Windows

Problem Statement

Many a times, we wish to monitor space left in disk then only allow to get log generated in disk. If it exceeded there should be a alarm raised regarding memory crunch.

Solution

The solution can be used for other purposes as well.

GetFolderSize(Provide the path)
{
     Call FindFirstFile to get handle
     {
         While(True)
         {   
            Check if it is not directory (.(current directory), ..(previous directory))
            Check if it is a directory
            If YES
            {
                   Call GetFolderSize recursively
            }
            else
            {
                   Keep account of file size
            }
            If FindNextFile successful
            {
                   Continue
            }
            Else
            {
                   Close Handle and break
            }
         }
     }
}

No comments:

Post a Comment