Solved

<cfdirectory> question

Posted on 2004-08-16
8
735 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

13 Experts available now in Live!

Get 1:1 Help Now