March 31, 2006

How to find the size of a directory?

Here is an article from coldfusion cookbook.

<cfdirectory  
  directory="c:\cfusionmx"  
  action="list"  
  recurse="true"  
  name="cfDir">
    
<cfquery dbtype="query" name="dirSize">
   select sum(size) as size from cfDir
</cfquery>

<cfset sizemb="dirSize.size/1000000">

<cfoutput>#numberFormat(sizeMB,",.99")#</cfoutput>

Note the ‘recurse’ option, this will get the size of the current and all sub-directories. If you only need the size of the current directory, change recurse to false.

© Michael Sharman 2017