Partager via


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))

dodir("c:\")

SELECT * FROM dirs ORDER BY size descending INTO CURSOR totals

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

oBrowse.AutoFit

PROCEDURE dodir(cPath) as Number

      LOCAL n,i,aa[1],nTotal

      nTotal=0

      n=ADIR(aa,cPath+"*.*","HD",1)

      FOR i = 1 TO n

            IF "D"$aa[i,5]

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

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

                  ENDIF

            ELSE

                  nTotal= nTotal+aa[i,2]

            ENDIF

      ENDFOR

      INSERT INTO dirs VALUES (cPath,nTotal)

      ?cPath,TRANSFORM(nTotal,"999,999,999,999")

RETURN 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

  • Anonymous
    June 15, 2005
    or you could use sequoiaview http://www.win.tue.nl/sequoiaview/
  • Anonymous
    June 15, 2005
    The comment has been removed
  • Anonymous
    June 16, 2005
    The comment has been removed
  • Anonymous
    June 16, 2005
    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
  • Anonymous
    June 17, 2005
    Several years ago, I saw a presentation from Microsoft Research about online communication in communities...
  • Anonymous
    June 17, 2005
    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 "."
  • Anonymous
    June 29, 2005
    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)
  • Anonymous
    July 12, 2008
    <a href= http://index1.oloire.com >joseph bruce and joseph ustler pics</a> <a href= http://index3.oloire.com >passover haggdah</a> <a href= http://index5.oloire.com >uspassportschangeofaddress</a> <a href= http://index4.oloire.com >houseless child in only need help lynn mass</a> <a href= http://index2.oloire.com >dipset music video codes</a>