Click here to Skip to main content
15,886,536 members
Articles / Desktop Programming / ATL

Folder Size Information in the Windows Explorer Details View

Rate me:
Please Sign up or sign in to vote.
4.59/5 (76 votes)
18 Aug 2010CPOL2 min read 444.6K   13.8K   80   96
This code displays the folder size information in the Explorer's Details view.
Sample Image - DirSize.jpg

Introduction

In day to day life, when one wants to know the size of a folder, (s)he has to right click on the folder name and has to choose the Properties. Using this DLL, one can view the folder size as one of the columns of the Explorer as shown in the image. We also have the facility to sort according to the folder size. (I did not do anything to sort, it is done by Explorer. :))

This class implements the Shell interface called IColumnProvider. Using this interface, one can customize the Explorer's Details view. This class adds one more column to the Details view, which displays the consolidated folder size.

To build this project, you must install Microsoft Platform SDK, or click here [53.5 KB] to download SHLOBJ.h.

How to Use the DLL

Well, if you build the project, you need not do anything, since the IDE automatically registers the DLL. If demo project is downloaded, then unzip the DLL and register it using the command "regsvr32 <Path of the unzipped DLL>". E.g., Regsvr32 c:\DirSize.DLL, if the DLL is present in C:.

Scope for Further Improvements

This code can be modified to display the number of files/folders in the folder. Or maybe, you can pack two more classes to display columns for number of files and number of folders into the same DLL to do so.

Performance Issues

When the user selects the "Folder Size" item from the Explorer context menu, the Explorer starts calculating the folder size by traversing all the files and nested folders. First time, it might take some minutes depending upon the contents of the folder. But all the operations are done in the background (Explorer is smart enough!.. Ehh). So this won't stop you from traversing through other files.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
India India
He is a graduate, currently working as a Software Engineer in Bangalore, India. You can reach him at sharan34@yahoo.com

Comments and Discussions

 
GeneralRe: commas Pin
Xun Ding4-May-05 9:35
Xun Ding4-May-05 9:35 
GeneralThanks! Pin
fuckmeplease22-Oct-04 18:09
fuckmeplease22-Oct-04 18:09 
Generalit would be more perfect if you correct just one line~ :) Pin
cutepsy28-Jul-04 22:02
susscutepsy28-Jul-04 22:02 
GeneralShow size in MB Pin
wilkinsonrayo26-May-04 9:29
wilkinsonrayo26-May-04 9:29 
GeneralRe: Show size in MB Pin
Z372131-May-04 2:53
Z372131-May-04 2:53 
GeneralRe: Show size in MB Pin
Spoony21-Aug-04 10:44
Spoony21-Aug-04 10:44 
GeneralRe: Show size in MB Pin
Jac7513-Oct-04 13:00
Jac7513-Oct-04 13:00 
GeneralRe: Show size in MB Pin
Ayaz Awan3-Oct-06 0:29
Ayaz Awan3-Oct-06 0:29 
Here is code which convert size into String, with respective postfixes like MB, GB, KB, B etc and also display round off fractions upto two digits.

//----------------------------------------------------------------------------
char * GetSizeString(unsigned long size,char str[])
{
char temp[100]="";

double dsize=size;
if (size==0)
{
ultoa(size,temp,10);
strcat(temp," KB");
}
else if (size<1024)
{
ultoa(size,temp,10);
strcat(temp," B");
}
else if (size<1048576)
{
ULONG rem=size/1024;
ULONG deciml=size- (rem*1024);
ultoa(rem,temp,10);

if (deciml!=0)
{
char temp1[10];
strcat(temp,".");
ultoa(deciml,temp1,10);
temp1[2]=NULL;
strcat(temp,temp1);
}

strcat(temp," KB");
}
else if (size < 1073741824)
{
//dsize /= 1048576.0;
ULONG rem=size/1048576;
ULONG deciml=size- (rem*1048576);
ultoa(rem,temp,10);

if (deciml!=0)
{
char temp1[10];
strcat(temp,".");
ultoa(deciml,temp1,10);
temp1[2]=NULL;
strcat(temp,temp1);
}


//doubleToString(dsize,temp,2);

//gcvt(dsize,5,temp);

strcat(temp," MB");

}
else
{
//dsize /= 1073741824.0;
ULONG rem=size/1073741824;
ULONG deciml=size- (rem*1073741824);
ultoa(rem,temp,10);

if (deciml!=0)
{
char temp1[10];
strcat(temp,".");
ultoa(deciml,temp1,10);
temp1[2]=NULL;
strcat(temp,temp1);
}

//gcvt(dsize,2,temp);
strcat(temp," GB");
}

strcpy(str,temp);
return str;
}
//--------------------------------------------------------------------------

Ayaz
GeneralRe: Show size in MB Pin
Axel Rietschin16-May-07 6:17
professionalAxel Rietschin16-May-07 6:17 
GeneralRe: Show size in MB Pin
perottol8-Jun-04 2:42
perottol8-Jun-04 2:42 
GeneralRe: Show size in MB Pin
MXX26-Dec-04 18:47
MXX26-Dec-04 18:47 
GeneralRe: Show size in MB Pin
schanka25-Feb-05 3:53
schanka25-Feb-05 3:53 
GeneralRe: Show size in MB Pin
ho0chieman28-Feb-05 13:34
ho0chieman28-Feb-05 13:34 
QuestionRe: Show size in MB Pin
Lonesan15-Jun-07 15:02
Lonesan15-Jun-07 15:02 
GeneralRe: Show size in MB Pin
robaxn16-Jul-05 23:27
robaxn16-Jul-05 23:27 
GeneralRe: Show size in MB Pin
JURAhasiok28-Aug-06 12:46
JURAhasiok28-Aug-06 12:46 
QuestionRe: Show size in MB Pin
Cosmo2b28-Jan-07 20:49
Cosmo2b28-Jan-07 20:49 
GeneralColumn alignment Pin
Claudius Mokler24-May-04 0:19
Claudius Mokler24-May-04 0:19 
GeneralSuggestion... Pin
dandy727-May-04 7:20
dandy727-May-04 7:20 
GeneralRe: Suggestion... Pin
m_harriss23-May-04 0:14
m_harriss23-May-04 0:14 
GeneralRe: Suggestion... Pin
m_harriss23-May-04 6:55
m_harriss23-May-04 6:55 
GeneralRe: Suggestion... Pin
Anonymous22-Jul-04 10:46
Anonymous22-Jul-04 10:46 
GeneralNo extra Column after registering dll Pin
Sorri6-May-04 23:45
Sorri6-May-04 23:45 
GeneralRe: No extra Column after registering dll Pin
Sorri6-May-04 23:48
Sorri6-May-04 23:48 
GeneralRe: No extra Column after registering dll Pin
Mr. GD (Mr.Green)19-Sep-16 6:13
professionalMr. GD (Mr.Green)19-Sep-16 6:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.