Solved

<cfdirectory> question

Posted on 2004-08-16
8
734 Views
Last Modified: 2013-12-24
how do I get <cfdirectory> to only display the files in the directory, not the folders?
0
Comment
Question by:JoshDale
  • 5
  • 2
8 Comments
 
LVL 21

Expert Comment

by:pinaldave
ID: 11816116
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
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11816133
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
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11816140
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
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11816146
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Accepted Solution

by:
anandkp earned 500 total points
ID: 11817662
<cfdirectory directory="C:/temp" name="dirQuery" action="LIST">
 
<cfoutput query="dirQuery">
      <cfif dirQuery.type IS "file">
            #dirQuery.name#<br>
      </cfif>
</cfoutput>

I dont see the need for the rest of the code [from above]
0
 

Author Comment

by:JoshDale
ID: 11825112
Simple answers get points, thanks.
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11825269
that is the way to go. :)
0
 
LVL 17

Expert Comment

by:anandkp
ID: 11827768
Thou i dont see why it was graded as B ...
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now