Running out of space ? What’s on your disk?

Often a hard disk gets close to full and undesirable things happen, especially on the volume that contains Windows. For example, suppose Windows Update is chugging along and runs out of space. How does it gracefully handle that?


How can you determine which folders take up the most space?


This recursive code creates a cursor with 2 fields per folder: the full path and the size.


CREATE CURSOR dirs (path c(250),size n(13,0))


SELECT * FROM dirs ORDER BY size descending INTO CURSOR totals

BROWSE FIELDS path,size:p="999,999,999,999" NAME oBrowse LAST NOWAIT



PROCEDURE dodir(cPath) as Number

      LOCAL n,i,aa[1],nTotal



      FOR i = 1 TO n

            IF "D"$aa[i,5]

                  IF aa[i,1] != '.'

                        nTotal= nTotal+dodir(cPath+aa[i,1]+"\")



                  nTotal= nTotal+aa[i,2]



      INSERT INTO dirs VALUES (cPath,nTotal)




The last parameter to ADIR preserves the CasE of the names. Notice the formatting of the large numbers with commas makes them much easier to read. The NAME clause of the BROWSE command creates an object named oBrowse which can then be manipulated, such as invoking the Autofit method.


Hidden, compressed, inaccessible (perhaps due to security) files, junction points can vary your results.


This SQL statement groups folder by folder depths (number of backslashes) and shows how many and how big they are.

SELECT OCCURS("\",path) as dep,COUNT(*),SUM(size) FROM dirs GROUP BY dep

My disk had folders 14 levels deep!



Comments (8)

  1. Neat little tip, Calvin…thanks!!

    Another amazing thing that you can do with the Fox and in short order, too!


  2. curtis says:

    Very nice!…but I have too many files in a DIR or too many DIR in a DIR and the aa array fills up and fails with invalid subscript. 🙁

    Any idea on a quick work around?

  3. Vassilis Aggelakos says:

    Nice Tip Calvin, but in machine (WinXP SP2)I was getting a stack overflow error. After a small debugging I found that the code needs:

    IF aa[i,1] != ‘.’ AND aa[i,1] != ‘..’

    instead of:

    IF aa[i,1] != ‘.’

    Many Thanx

  4. Several years ago, I saw a presentation from Microsoft Research about online communication in communities…

  5. Calvin_Hsia says:

    If you’re getting an error due to "." and "..", then you have SET EXACT ON for string compares, which is not the default. With SET EXACT OFF, cStr="." is true for any string starting with "."

  6. andré k. says:

    Hello bloggers here, all your stack overflow and memory shortage problems could disapear, and program will speed 100 times up, if someone(A "true" CPP guru, I mean) could translate this Visual Basic bullsh… in CPP. (e.g. a VC7_1 zipped project)

  7. Olgunka-ww says:

    <a href= >joseph bruce and joseph ustler pics</a> <a href= >passover haggdah</a> <a href= >uspassportschangeofaddress</a> <a href= >houseless child in only need help lynn mass</a> <a href= >dipset music video codes</a>

Skip to main content