How do I find the size of a directory?

Use the <cfdirectory> tag, and then do a query of queries on the results:

<cfdirectory 
	directory="c:\cfusionmx"
	action="list"
	name="cfDir"
	recurse="true">
<cfquery dbtype="query" name="dirSize">
	select sum(size) as size from cfDir
</cfquery>
<cfset sizeMb = dirSize.size/1000000>
<cfoutput>#numberFormat(sizeMB,",.99")#</cfoutput>

In the example above, the result is modified to return a value in megabytes. Also note the use of recurse="true" in the <cfdirectory> tag. This will return all the files including those beneath the directory specified. If you only want the size of the files in the directory itself, change recurse to false.

This question was written by Jacob Munson
It was last updated on March 31, 2006.

Categories

File and Directory Access

Comments

comments powered by Disqus