(#directory#)(DIR)#name#
(#directory#)(FILE)#name# - #size# bytes
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => RoBsTaMaCk [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> CFDIRECTORY - RECURSIVE LOOK IN - Coldfusion - Advanced Techniques

CFDIRECTORY - RECURSIVE LOOK IN - Coldfusion - Advanced Techniques

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

  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. #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 (raycamdenfamily.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

  3. #3

    Default Re: CFDIRECTORY - RECURSIVE LOOK IN

    Thank you ! It is working ...
    maquejp Guest

Similar Threads

  1. cfdirectory and Flash
    By Rowan in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: July 19th, 02:58 PM
  2. How do I use CFtree and CFdirectory?
    By fvanstaveren in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 5th, 04:38 PM
  3. URL Shortcuts in CFDIRECTORY?
    By remecTim in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 4th, 04:23 PM
  4. sorting in <cfdirectory>
    By joonstar in forum Macromedia ColdFusion
    Replies: 1
    Last Post: May 3rd, 10:59 AM
  5. CFC , CFDIRECTORY into Array
    By stebennettsjb in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: March 9th, 12:07 PM

Bookmarks

Posting Permissions

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