Link to home
Start Free TrialLog in
Avatar of JoshDale
JoshDale

asked on

<cfdirectory> question

how do I get <cfdirectory> to only display the files in the directory, not the folders?
Avatar of pinaldave
pinaldave
Flag of India image

Hi JoshDale,
<cfdirectory
   action = "directory action"
   directory = "directory name"
   name = "query name"
   filter = "list filter"
   mode = "permission"
   sort = "sort specification"
   newDirectory = "new directory name">

now what you can do is in filter is make it like *.* or something..
there is nothing specific which can only filter file and not the folder in coldfusion.

so if you use the filter like *.* it will bring all the files but if there is dot in the name of the folder it will bring that too... so you can do like this
*.??? and it will bring the files probably.

Regards,
---Pinal
Hi JoshDale,
also there is one good piece of code on the macromedia site which brings all the directory ( just opposite to what you want but still good to know may be we can use it)
<cfdirectory directory="C:/temp" name="dirQuery" action="LIST">
 To list only directories, you must loop over the query returned by cfdirectory and test the type field.
The following example creates both an array of directory names and a query that contains entries for the directories only.
<!--- Get an array of directory names. --->
<cfset dirsArray=arraynew(1)>
<cfset i=1>
<cfloop query="dirQuery">
<cfif dirQuery.type IS "dir">
<cfset dirsArray[i]=dirQuery.name>
<cfset i = i + 1>
</cfif>
</cfloop>
<cfdump var="#dirsArray#">
<br>
<!--- Get all directory information in a query of queries.--->
<cfquery dbtype="query" name="dirsOnly">
SELECT * FROM dirQuery
WHERE TYPE='Dir'
</cfquery>
<cfdump var="#dirsOnly#">

Regards,
---Pinal
Hi JoshDale,

Ignore my first messsage. this is the answer to your question.
<cfdirectory directory="C:/temp" name="dirQuery" action="LIST">
 
<!--- Get an array of directory names. --->
<cfset dirsArray=arraynew(1)>
<cfset i=1>
<cfloop query="dirQuery">
<cfif dirQuery.type IS "file">
<cfset dirsArray[i]=dirQuery.name>
<cfset i = i + 1>
</cfif>
</cfloop>
<cfdump var="#dirsArray#">
<br>
<!--- Get all directory information in a query of queries.--->
<cfquery dbtype="query" name="dirsOnly">
SELECT * FROM dirQuery
WHERE TYPE='Dir'
</cfquery>
<cfdump var="#dirsOnly#">



Regards,
---Pinal
Hi JoshDale, Typo fixed.
<cfdirectory directory="C:/temp" name="dirQuery" action="LIST">
 To list only directories, you must loop over the query returned by cfdirectory and test the type field.
The following example creates both an array of directory names and a query that contains entries for the directories only.
<!--- Get an array of directory names. --->
<cfset dirsArray=arraynew(1)>
<cfset i=1>
<cfloop query="dirQuery">
<cfif dirQuery.type IS "file">
<cfset dirsArray[i]=dirQuery.name>
<cfset i = i + 1>
</cfif>
</cfloop>
<cfdump var="#dirsArray#">
<br>
<!--- Get all directory information in a query of queries.--->
<cfquery dbtype="query" name="dirsOnly">
SELECT * FROM dirQuery
WHERE TYPE='file'
</cfquery>
<cfdump var="#dirsOnly#">


Regards,
---Pinal
ASKER CERTIFIED SOLUTION
Avatar of anandkp
anandkp
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JoshDale
JoshDale

ASKER

Simple answers get points, thanks.
that is the way to go. :)
Thou i dont see why it was graded as B ...