Modifying Treepie To Display File Count

I’ve already talked a bit about managing large amounts of files in my post Disk efficiency when dealing with tons of small files so you can kind of tell that I’m a proponent of having as little files on disk as possible (but not less). In my everyday tasks I’m using this program called Everything by David Carpenter and I suggest you check it out if you don’t know it yet. The concept is simple, but the consequences are immense – the program indexes all the files and folders on all volumes connected to your computer i.e. your hard disk drives, flash drives, cd/dvd-roms, etc. And it tracks the changes so this index is always up-to-date allowing you very fast access to ANY FILE on your computer. The thing is that it indexes all the files on startup so the more files you have the longer it takes. To illustrate another reason why too many files aren’t great see the picture below.

Notice how the actual size of the files is about 806KB while because there are so many files (4422 to be exact) and the cluster size for my disk is 4KB the actual space occupied on the drive totals up to almost 18MB. We can do the math to better understand what happened:

cluster size: 4KB = 4096 Bytes

number of files: 4422

so even if each file contained only a single character i.e. file size of 1 Byte it would occupy the whole cluster and take up 4KB of disk space. Which means that the absolute minimum of disk space consumed by these files is 4422 x 4096 = 18112512 Bytes ~= 17.27 MB

And of course if the files are larger they will take up even more space. Hopefully I convinced you that you should remove any and all unnecessary files that you’re not using and don’t just let them hinder your drive’s performance. This is the part where we have to find a way to locate directories containing the most files so that we could decide whether we actually need them or not. In the past I’ve been using a program called TreePie to find which directories occupy the most space on disk. It looks something like this:

Unfortunately it displays the folders proportional only to the space occupied on disk. On the other hand the project is open source so I can modify it’s behavior and so I did. Here’s the patch file with my changes.

Index: AllDir.cpp
--- AllDir.cpp  (revision 16)
+++ AllDir.cpp  (working copy)
@@ -64,7 +64,7 @@
    HANDLE hFirst;
    WIN32_FIND_DATA hFind;
-   INT64 nSize =;
+   INT64 nSize = -2;

    char sCompleteFile[MAX_PATH];
    char sListFile[MAX_PATH];
@@ -131,7 +131,7 @@
            if (hFind.nFileSizeHigh!=-858993460 ) //// ARRRGH!(system information folder)
                //grandezza del file (aritmetica a 64 bit)
-               nSize += (INT64)hFind.nFileSizeHigh * ((INT64)MAXDWORD+1) + hFind.nFileSizeLow ;
+               nSize ++;
                //if (nSize > MAXDWORD){
                //  mb_log("ListAllDir: nSize sorpassa MAXDWORD");
Index: displayer.cpp
--- displayer.cpp   (revision 16)
+++ displayer.cpp   (working copy)
@@ -62,11 +62,7 @@

                glRasterPos2f(5.0f , rect.bottom - 20.0f );
-               if (iv_nSize > 1073741824 )
-                   glPrint("%d GB  ",iv_nSize/1073741824);
-               else
-                   glPrint("%d MB  ",iv_nSize/1048576);
-               glPrint("(%d KB  )",iv_nSize/1024);
+               glPrint("%d files",iv_nSize);

                glRasterPos2f(rect.right/2.0f , rect.bottom - 20.0f );

Pretty simple, huh? These changes are enough to get TreePie to start displaying the file count instead of the file size. Though I have to admit that I was unable to open and compile it with Microsoft’s Visual Studio Express. I’m still not sure if it was something with included project files or was it something with my machine’s configuration. I solved it by using an IDE that I have more experience with – CodeBlocks. I created a new project, copied over the files and soon I had my own modified version of TreePie. Which I’m happy to share with you all. Here’s an archive containing the modified Treepie version as a CodeBlocks project and includes a compiled version if you don’t have this IDE or don’t want to install it. I’m considering forking this project, cleaning up the code a little bit and maybe throwing in a few new features.