Solved

<cfdirectory> question

Posted on 2004-08-16
8
737 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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