Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

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 at 12:45:51 PM EDT.

CFML Referenced

<cfquery>
<cfif>
<cfoutput>

Categories

File and Directory Access

Comments

There are no comments for this entry.