How to Find the Size of a Directory?

Here is an article from coldfusion cookbook.

1
2
3
4
5
6
7
8
9
10
11
12
13
<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.

Comments