How do I get a listing of just the files or child directories in a directory?

You can use the cfdirectory tag with the list option, and then there are

two ways to only display the directories. The first option is to use

<cfif> to filter on 'type':

<cfdirectory directory="C:/Apache2/htdocs" action="list" name="dirResults">
<cfoutput query="dirResults">
	<cfif dirResults.type eq "dir">#dirResults.name#<br /></cfif>
</cfoutput>

The second option is to do a query of queries to filter the results:

<cfdirectory directory="C:/Apache2/htdocs" action="list" name="dirResults">
<cfquery name="dirFilter" dbtype="query">
	select name from dirResults
	where lower(type) = 'dir'
</cfquery>
<cfoutput query="dirFilter">
	#name#<br />
</cfoutput>

This question was written by Jacob Munson
It was last updated on September 8, 2006.

Categories

File and Directory Access

Comments

comments powered by Disqus