Solved

list directory and sub directory of a given path in ColdFusion

Posted on 2006-11-10
6
333 Views
Last Modified: 2013-12-24
here is my example but how can I list another directory like budget in my example

I would like to to modify this path, to any path I choose.

<!---------------------------------------------------------------------
This example shows the use of cfdirectory to display
the contents of the directory in where the current
<this file name>.cfm is located.
---------------------------------------------------------------------->
<html>
<head>
<title>
cfdirectory Example
</title>
</head>
<body>
<H1>cfdirectory Example</H1>
<!--- use cfdirectory to give the contents of the snippets directory,
order by name and size (you may need to modify this path) --->
<h3>cfdirectory Example</h3>
<!--- use cfdirectory to give the contents of the snippets directory,
order by name and size (you may need to modify this path) --->
<cfset x = "/Inet_findev/budget/">
<cfoutput>
list last dir: #listlast(x,'/')#<br>
</cfoutput>

<cfoutput>
directory="#GetDirectoryFromPath(GetTemplatePath())#"
</cfoutput>

<cfdirectory
  directory="#GetDirectoryFromPath(GetTemplatePath())#"
  name="myDirectory"
  sort="name ASC, size DESC, datelastmodified">
<!---- Output the contents of the cfdirectory as a cftable ----->
<cftable
  query="myDirectory"
  colSpacing = "10"
  htmltable
  colheaders>
  <cfcol
    header="NAME:"
    align = "Left"
    width = 20
    text="#Name#">
  <cfcol
    header="SIZE:"
    align = "Left"
    width = 20
    text="#Size#">
  <cfcol
    header="date last modified:"
    align = "Left"
    width = 20
    text="#datelastmodified#">
</cftable>
</body>
</html>
0
Comment
Question by:rapace3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17918894
This should work:
<cfset x = "foldername">

<cfoutput>
directory="#GetDirectoryFromPath(ExpandPath(x))#"
</cfoutput>

<cfdirectory
  directory="#GetDirectoryFromPath(ExpandPath(x))#"
  ....

You can also do paths like:
<cfset x = "../../">
<cfset x = "../../differentfoldername">

0
 

Author Comment

by:rapace3
ID: 17919510
the C.cfm is in E:\Inet_findev\benchmark\
~~~~~~~~ C.cfm
<cfset x = "../budget">
<cfoutput>
x = #x#<BR>
GetDirectoryFromPath(ExpandPath(x))="#GetDirectoryFromPath(ExpandPath(x))#"<BR>
directory="#GetDirectoryFromPath(ExpandPath(x))#"<BR>
</cfoutput>
      <cfdirectory
        
  directory="#GetDirectoryFromPath(ExpandPath(x))#"
        
         name = "myDirectory" SORT = "name ASC, size DESC">
      <!--- Output the contents of the cfdirectory as a CFTABLE --->
      <cftable query = "myDirectory">
         <cfcol header = "NAME:" text = "#Name#">
      <cfcol header = "SIZE:" text = "#Size#">
      </cftable>
~~~~~~~~~~~~~~~~~~~
result

x = ../budget
GetDirectoryFromPath(ExpandPath(x))="E:\Inet_findev\"
directory="E:\Inet_findev\"
0
 

Author Comment

by:rapace3
ID: 17932649
Here is the answer I was looking for

<FORM action="AA.cfm" METHOD="post">
<h3>Enter the name of a file in this directories <I>
<FONT SIZE="-1">
( try ../*.* )<!---E:\Inet_findev\---><br>
( try ../budget/*.* )<!---E:\Inet_findev\budget\---><br>
( try ../benchmark/*.* )<!---E:\Inet_findev\benchmark\---><br>
( try ../benchmark/test/*.* )<!---E:\Inet_findev\benchmark\---><br>
</FONT> </I></h3>
<INPUT TYPE="Text" NAME="myDir">
<INPUT TYPE="Submit" NAME="">
<cfset myDir="../benchmark/*.*">
<cfoutput>
<br>
The current directory is: #myDir#
</cfoutput>
</form>
<!---
<cfset thisPath=ExpandPath("../budget/*.*")>
--->
<cfset thisPath=ExpandPath("#Form.myDir#")>
<cfset thisDirectory=GetDirectoryFromPath(thisPath)>
<cfoutput>
The current directory is: #GetDirectoryFromPath(thisPath)#
</cfoutput>

<!---
<CFDIRECTORY action="LIST" name="dir" directory="#getdirectoryfrompath(expandpath("*.*"))#">
--->
<CFDIRECTORY action="LIST" name="dir" directory="#thisDirectory#">
<CFSET myQuery = QueryNew("name, size, type, DateLastModified, Attributes, Mode, Ext")>
<CFSET newRow  = QueryAddRow(MyQuery, dir.recordcount)>

<CFOUTPUT query="dir">
<CFSET temp = QuerySetCell(myQuery, "name", name, currentrow)>
<CFSET temp = QuerySetCell(myQuery, "size", size, currentrow)>
<CFSET temp = QuerySetCell(myQuery, "type", type, currentrow)>
<CFSET temp = QuerySetCell(myQuery, "DateLastModified", DateLastModified, currentrow)>
<CFSET temp = QuerySetCell(myQuery, "Attributes", Attributes, currentrow)>
<CFSET temp = QuerySetCell(myQuery, "Mode", Mode, currentrow)>
<CFSET temp = QuerySetCell(myQuery, "Ext", LISTLAST(name,"."), currentrow)>
</cfoutput>

<cfquery dbtype="query" name="sorted">
     SELECT *
     FROM myQuery
--     WHERE type <> 'Dir'
     ORDER BY DateLastModified DESC
</cfquery>
 
<CFDUMP var="#sorted#">
0
 

Author Comment

by:rapace3
ID: 17932665
I have answer to my own question, How do I accept that answer?
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18153455
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

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

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Collapseable list of URLs. 10 100
SSL sertificate 5 48
listing all functions in JavaScript 19 114
WEB Farm 6 26
Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

747 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

12 Experts available now in Live!

Get 1:1 Help Now