Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
maquejp #1
CFDIRECTORY - RECURSIVE LOOK IN
Hello,
I would like to know the size of a specific directory; files+ subfolders files.
I am trying to do a recursive function but it does not returns what I want...
Here is the scripts:
<cfset sRoot="#GetDirectoryFromPath(GetTemplatePath())#">
<cfoutput>#sRoot#</cfoutput><br />
<cfoutput>#DirectoryList(sRoot)#</cfoutput>
<cffunction access="public" name="DirectoryList" output="true">
<cfargument name="var" type="string" required="yes" default="string">
<cfdirectory directory="#var#" name="mysubdirectory" sort="type asc, size
ASC, name DESC">
<cfloop query="mysubdirectory">
<cfoutput>
<cfif #mysubdirectory.type# eq "Dir">
(#var#)(DIR)#mysubdirectory.name#<BR />
<cfset var2 = #var# & #mysubdirectory.name# & "/">
<cfoutput>#DirectoryList(var2)#</cfoutput>
<cfelse>
(#var#)(FILE)#mysubdirectory.name# - #mysubdirectory.size# bytes<BR />
</cfif>
</cfoutput>
</cfloop>
</cffunction>
So it start, do in the first subfolder and list the files within, then it does
back and displays always the same file name which is the first within the
subfolder...
/dev/tests/tests_maqueje/
(/dev/tests/tests_maqueje/)(DIR)upload
(/dev/tests/tests_maqueje/upload/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)prizee.txt - 10 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)globe_03.jpg - 1793 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)activity_codes_inot_database.xls -
19968 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)Winter2.jpg - 105542 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)Winter1.jpg - 105542 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)Winter.jpg - 105542 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)service-guide-direction_c2.pdf -
272476 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)dictionnaire_fr-lu.pdf - 750391 bytes
(/dev/tests/tests_maqueje/upload/)(FILE)Getting_Started.pdf - 2363632 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
(/dev/tests/tests_maqueje/)(FILE)prizee1.txt - 10 bytes
Any body can help me with this?
Thank you!
maquejp Guest
-
cfdirectory and Flash
Hi there, I have a small CFC that reads the contents of a directory and returns the results to a flash application. Here is the CFC (pretty... -
How do I use CFtree and CFdirectory?
I'm trying to create a form, much like the administrator form, that will allow users in my development group to seclect a DSN and associate it with... -
URL Shortcuts in CFDIRECTORY?
I'm making a very basic shared document directory on our intranet, mostly just by using CFDIRECTORY to list things out. Of course, a new... -
sorting in <cfdirectory>
code <cfdirectory directory='#GetDirectoryFromPath(GetTemplatePath())#' name='myDirectory' sort='name'> <cftable query='myDirectory'... -
CFC , CFDIRECTORY into Array
Hi, im trying to create a CFC that looks into a folder and returns all the files into an arrya that i will put into flash.. at the moment when i... -
RoBsTaMaCk #2
Re: CFDIRECTORY - RECURSIVE LOOK IN
Ok, I think the problem might have had something to do with the way Coldfusion
stores <cfdirectory> queries in memory (although this seemed rather unlikely).
The example attached uses the 'directoryList' function from the Common Function
Library Project @ [url]http://www.cflib.org[/url]
Maybe you can figure out a way to whittle this down and do a direct text
output versus storing everything to a query first. Hope this helps.
-=Rob W
<!---
This library is part of the Common Function Library Project. An open source
collection of UDF libraries designed for ColdFusion 5.0. For more information,
please see the web site at:
[url]http://www.cflib.org[/url]
Warning:
You may not need all the functions in this library. If speed
is _extremely_ important, you may want to consider deleting
functions you do not plan on using. Normally you should not
have to worry about the size of the library.
License:
This code may be used freely.
You may modify this code as you see fit, however, this header, and the header
for the functions must remain intact.
This code is provided as is. We make no warranty or guarantee. Use of this
code is at your own risk.
--->
<!---
Mimics the cfdirectory, action="list" command.
Updated with final CFMX var code.
Fixed a bug where the filter wouldn't show dirs.
@param directory The directory to list. (Required)
@param filter Optional filter to apply. (Optional)
@param sort Sort to apply. (Optional)
@param recurse Recursive directory list. Defaults to false. (Optional)
@return Returns a query.
@author Raymond Camden (ray@camdenfamily.com)
@version 2, April 8, 2004
--->
<cffunction name="directoryList" output="false" returnType="query">
<cfargument name="directory" type="string" required="true">
<cfargument name="filter" type="string" required="false" default="">
<cfargument name="sort" type="string" required="false" default="">
<cfargument name="recurse" type="boolean" required="false" default="false">
<!--- temp vars --->
<cfargument name="dirInfo" type="query" required="false">
<cfargument name="thisDir" type="query" required="false">
<cfset var path="">
<cfset var temp="">
<cfif not recurse>
<cfdirectory name="temp" directory="#directory#" filter="#filter#"
sort="#sort#">
<cfreturn temp>
<cfelse>
<!--- We loop through until done recursing drive --->
<cfif not isDefined("dirInfo")>
<cfset dirInfo =
queryNew("attributes,datelastmodified,mode,name,si ze,type,directory")>
</cfif>
<cfset thisDir = directoryList(directory,filter,sort,false)>
<cfif server.os.name contains "Windows">
<cfset path = "\">
<cfelse>
<cfset path = "/">
</cfif>
<cfloop query="thisDir">
<cfset queryAddRow(dirInfo)>
<cfset querySetCell(dirInfo,"attributes",attributes)>
<cfset querySetCell(dirInfo,"datelastmodified",datelastmo dified)>
<cfset querySetCell(dirInfo,"mode",mode)>
<cfset querySetCell(dirInfo,"name",name)>
<cfset querySetCell(dirInfo,"size",size)>
<cfset querySetCell(dirInfo,"type",type)>
<cfset querySetCell(dirInfo,"directory",directory)>
<cfif type is "dir">
<!--- go deep! --->
<cfset directoryList(directory & path & name,filter,sort,true,dirInfo)>
</cfif>
</cfloop>
<cfreturn dirInfo>
</cfif>
</cffunction>
<!--- // Parameters for directoryList // --->
<cfparam name="directory" default="#mid(
GetDirectoryFromPath(GetTemplatePath()), 1, len(
GetDirectoryFromPath(GetTemplatePath()) ) -1 )#">
<cfparam name="filter" default="">
<cfparam name="sort" default="type asc, size ASC, name DESC">
<cfparam name="recurse" default="true">
<!--- // Store the recursive directory query to 'temp' // --->
<cfset dirlist = directoryList( directory, filter, sort, recurse )>
<!--- // Output the data in the specified format // --->
<cfoutput query="dirlist">
<cfif type eq "Dir">
(#directory#)(DIR)#name#<BR />
<cfelse>
(#directory#)(FILE)#name# - #size# bytes<BR />
</cfif>
</cfoutput>
RoBsTaMaCk Guest
-



Reply With Quote

