CFDIRECTORY - RECURSIVE LOOK IN

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. sorting in <cfdirectory>
      code <cfdirectory directory='#GetDirectoryFromPath(GetTemplatePath())#' name='myDirectory' sort='name'> <cftable query='myDirectory'...
    5. 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...
  3. #2

    Default 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=&quot;list&quot; 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

  4. #3

    Default Re: CFDIRECTORY - RECURSIVE LOOK IN

    Thank you ! It is working ...
    maquejp Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139