Solved

Using CFDIRECTORY

Posted on 2003-11-05
3
161 Views
Last Modified: 2013-12-24
OK, here is the issue.

I want to loop through my directory and create the following look (SEE BELOW), I will use "wwwroot" as my base folder. I think you get the poit.  I basilcally want to create a "windows explorer" type view (although just have them all expanded).  This stuff is so easy in .asp, but being new to coldfusion.  I am at a bit of a loss.

wwwroot (dir)
    - File1.cfm (file)
    - File2.cfm (file)
    - File3.cfm (file)
      FOLDER1 (dir)
        - File1.cfm (file)
        - File2.cfm (file)
        FOLDER1a (dir)
          - File1a.cfm (file)
      FOLDER2 (dir)
        - File2a.cfm(file)
0
Comment
Question by:turbosig
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 200 total points
ID: 9691274
<cfif isDefined('attributes.dirPath')>
      <cftry>
            <cfset path=#expandPath(#attributes.dirPath#)#>
      <cfcatch>
            <cfset path=#attributes.dirPath#>
      </cfcatch>
      </cftry>
      <cfif right(path,1) eq '\'>
            <cfset path=left('#attributes.dirPath#',len('#attributes.dirPath#')-1)>
      <cfelse>
            <cfset path=#attributes.dirPath#>
      </cfif>
</cfif>
<cfif not isdefined('attributes.spacer')>
      <cfset locSpacer = 1>
<cfelse>
      <cfset locSpacer = #attributes.spacer# + 1>
try this

savt this code bloack as dirRecursive.cfm


</cfif>
<cfset strInset='&nbsp;'>
<cfloop index="idx" from="1" to="#locSpacer#">
      <cfset strInset = #strInset# & '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'>
</cfloop>

<cfdirectory action="list" directory="#path#" name="fileList" sort="type desc">
<cfloop query="fileList">
<cfif #type# is "dir" and #name# neq "." and #name# neq "..">
<cfoutput>#strInset#-#Name#<br></cfoutput>
<CF_dirRecursive dirPath="#attributes.dirPath#\#name#" spacer="#locSpacer#">
<cfelse>
<cfoutput>#strInset#-#Name# - #size#<br></cfoutput>
</cfif>
</cfloop>


and in the page that you want the directory list to appear

insert this line

<cf_dirRecursive dirPath="#expandPath('.')#" spacer="2">

the dirrecursive.cfm must be in the same directory as the page with the calling statement
0
 
LVL 2

Author Comment

by:turbosig
ID: 9691422
Thanks.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9693673
np

glad i could help
0

Featured Post

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

22 Experts available now in Live!

Get 1:1 Help Now