rapace3
asked on
list directory and sub directory of a given path in ColdFusion
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="#GetDirectoryFr omPath(Get TemplatePa th())#"
</cfoutput>
<cfdirectory
directory="#GetDirectoryFr omPath(Get TemplatePa th())#"
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>
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="#GetDirectoryFr
</cfoutput>
<cfdirectory
directory="#GetDirectoryFr
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>
ASKER
the C.cfm is in E:\Inet_findev\benchmark\
~~~~~~~~ C.cfm
<cfset x = "../budget">
<cfoutput>
x = #x#<BR>
GetDirectoryFromPath(Expan dPath(x))= "#GetDirec toryFromPa th(ExpandP ath(x))#"< BR>
directory="#GetDirectoryFr omPath(Exp andPath(x) )#"<BR>
</cfoutput>
<cfdirectory
directory="#GetDirectoryFr omPath(Exp andPath(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(Expan dPath(x))= "E:\Inet_f indev\"
directory="E:\Inet_findev\ "
~~~~~~~~ C.cfm
<cfset x = "../budget">
<cfoutput>
x = #x#<BR>
GetDirectoryFromPath(Expan
directory="#GetDirectoryFr
</cfoutput>
<cfdirectory
directory="#GetDirectoryFr
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(Expan
directory="E:\Inet_findev\
ASKER
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\budge t\---><br>
( try ../benchmark/*.* )<!---E:\Inet_findev\bench mark\--->< br>
( try ../benchmark/test/*.* )<!---E:\Inet_findev\bench mark\--->< 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("../bu dget/*.*") >
--->
<cfset thisPath=ExpandPath("#Form .myDir#")>
<cfset thisDirectory=GetDirectory FromPath(t hisPath)>
<cfoutput>
The current directory is: #GetDirectoryFromPath(this Path)#
</cfoutput>
<!---
<CFDIRECTORY action="LIST" name="dir" directory="#getdirectoryfr ompath(exp andpath("* .*"))#">
--->
<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#">
<FORM action="AA.cfm" METHOD="post">
<h3>Enter the name of a file in this directories <I>
<FONT SIZE="-1">
( try ../*.* )<!---E:\Inet_findev\---><
( try ../budget/*.* )<!---E:\Inet_findev\budge
( try ../benchmark/*.* )<!---E:\Inet_findev\bench
( try ../benchmark/test/*.* )<!---E:\Inet_findev\bench
</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("../bu
--->
<cfset thisPath=ExpandPath("#Form
<cfset thisDirectory=GetDirectory
<cfoutput>
The current directory is: #GetDirectoryFromPath(this
</cfoutput>
<!---
<CFDIRECTORY action="LIST" name="dir" directory="#getdirectoryfr
--->
<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#">
ASKER
I have answer to my own question, How do I accept that answer?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<cfset x = "foldername">
<cfoutput>
directory="#GetDirectoryFr
</cfoutput>
<cfdirectory
directory="#GetDirectoryFr
....
You can also do paths like:
<cfset x = "../../">
<cfset x = "../../differentfoldername