WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Check Used Disk Space


;====================================================================
; author  : jjd 
; purpose : give size of sub-directories for a user choosen directory
; date    : 8 october 2004
; input   : user choosen directory with AskDirectory call
; output  : file 'size*...' shown with notepad
;           output has a unique name with date
; version : 1.0
;====================================================================
; for example
; produces a listing containing :


;             Directory F:\cygwin\
;
;
;             bin  =>  66,072,576 
;             lib  =>  35,778,560
;             var  =>  12,087,296 
;             etc  =>   8,892,416
;             sbin =>     102,400
;             tmp  =>       4,096 
;             home =>       4,096
;====================================================================

IntControl(29, @TAB, 0, 0, 0)
;choose directory
;----------------
ou_je_suis=dirget()
flags=1|2
dir1=AskDirectory("Select Directory", "", "","Are you sure?",flags)
DirChange(dir1)
a = DirItemize("*.*")
count = ItemCount(a, @TAB)

;let winbatch computes disk size
;-------------------------------
d=ArrDimension(count+1)
size=ArrDimension(count+1)
for i=1 to count
d[i] = ItemExtract(i, a, @TAB)
size[i]=Dirsize(d[i],1)
next

DirChange(ou_je_suis)

;brute sort by size 
;------------------
for i=1 to count
	for j=i to count
		if( size[j] >= size[i]) then			
			x=size[i]
			n=d[i]
			size[i]=size[j]
			d[i]=d[j]
			size[j]=x
			d[j]=n	
		endif
	next
next
msg=""

; find max length of directory name
;----------------------------------
l=0
k=count
; to limit up to 10 most charged directories
;if( count > 10)then k=10
for i=1 to k
	if(strlen(d[i])> l) then l=strlen(d[i])
next
; fix directory name up to 20
if( l > 20) then l=20

;choose your numeric separator
separator=","   ;us separator
;separator=" "  ; french separator

; format output
;--------------
for i=1 to k 
        ; format size number with comma separator
        j=size[i]
        c="%j%"
        if( StrIndex(c, "+", 1, @FWDSCAN) > 0 )then ; we have floating point >1giga
          x=c ; we have floating point
        else
          f=strlen(c) mod 3
          x=""
          if(f != 0)then x=strcat(strfixleft(strsub(c,1,f)," ",3),separator)
          f=f+1
          for j=f to strlen(c) 
        	  y=strsub(c,j,3)
        	  x=strcat(x,y,separator)
        	  j=j+2
          next
          x=strsub(x,1,strlen(x)-1)
        endif
	msg=strcat(msg,strfix(d[i]," ",l)," => ",strfixleft(x," ",21),@crlf)
next

; build a unique name
;--------------------
fileout=strcat("size_of_",dir1,Timedate( ),".txt")
fileout=StrReplace(fileout," ","_")
fileout=StrReplace(fileout,"\","_")
fileout=StrReplace(fileout,"/","_")
fileout=StrReplace(fileout,":","_")

;write output to fileout
;-----------------------
handle = FileOpen(fileout, "WRITE")
FileWrite(handle,strcat("Winbatch generated listing ",Timedate( ),@crlf))
FileWrite(handle, strcat("Directory ",dir1,@crlf))
FileWrite(handle, msg)
FileClose(handle)

;show output
;-----------
run("notepad.exe",fileout)

Article ID:   W16714
File Created: 2005:02:18:12:21:58
Last Updated: 2005:02:18:12:21:58