Welcome to MSDN Blogs Sign in | Join | Help

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!

 

 

Published Wednesday, June 15, 2005 2:28 PM by Calvin_Hsia
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Running out of space ? What's on your disk?

Wednesday, June 15, 2005 3:37 PM by xarph
or you could use sequoiaview http://www.win.tue.nl/sequoiaview/

# re: Running out of space ? What's on your disk?

Wednesday, June 15, 2005 9:32 PM by Michael Babcock
Neat little tip, Calvin...thanks!!

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

--Michael

# re: Running out of space ? What's on your disk?

Thursday, June 16, 2005 3:51 PM by curtis
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?

# re: Running out of space ? What's on your disk?

Friday, June 17, 2005 3:15 AM by Vassilis Aggelakos
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

# What is taking up the space on your hard disk? TreeMap it!

Friday, June 17, 2005 7:41 PM by Calvin Hsia's WebLog
Several years ago, I saw a presentation from Microsoft Research about online communication in communities...

# re: Running out of space ? What's on your disk?

Saturday, June 18, 2005 2:46 AM by Calvin_Hsia
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 "."

# re: Running out of space ? What's on your disk?

Thursday, June 30, 2005 5:17 AM by andré k.
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)

# Good site

Sunday, July 13, 2008 4:37 AM by Olgunka-ww

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

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker