Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfdirectory

Explorer ,
Dec 01, 2008 Dec 01, 2008
I'd like to loop through the folders showing documents within them, and documents within folders of folders.

Is it possible to use cfdirectory to do this?

Could I use cfinclude somehow to loop though each folder?

Thanks in advance
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 01, 2008 Dec 01, 2008
Hi,

Try the "CFFM" opensource application @ riaforge,

http://cffm.riaforge.org/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 01, 2008 Dec 01, 2008
matthisco wrote:
> I'd like to loop through the folders showing documents within them, and
> documents within folders of folders.
>
> Is it possible to use cfdirectory to do this?

<cfdirectory directory="dir" recurse="yes">

--
Mack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 01, 2008 Dec 01, 2008
Thanks for your reply.

I've found the recurse attribute that works to an extent.

Would it be possible to determine what documents are where and indent them for each folder, so its displayed like a folder tree?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 01, 2008 Dec 01, 2008
Is there a way to determine folders within folders?

The recurse option just blurts everthing out regardless of nested folders.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 02, 2008 Dec 02, 2008
Bumping for answers

I'd like to display the documents for each folder underneath the folder to which they belong. I'd like to display them in a div, and hide show the div, when the foldername is clicked. So its like an explorer view.

Can anyone help?

I have some code below, it doesnt work, but at least its a startpoint

<cfparam name="path" default="">
<cfparam name="counter" default="">
<cfif path neq "">
<cfset path = path & dir>
<cfelse>
<cfset path = path>
</cfif>
<cfdirectory action="list" directory="c:\inetpub\wwwroot\documents" name="getem" recurse="yes" >

<cfoutput query="getem">
<cfif counter eq "">
<cfset counter = 1>
<cfelse>
<cfset counter = counter + 1>
</cfif>


<cfif type eq "dir">
<p>Folder name
<div id="#counter#">
Documents contained within folder
</div>
</p>
</cfif>
</cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 02, 2008 Dec 02, 2008
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 02, 2008 Dec 02, 2008
hi,

cfdirectory gives you more than just the file names, it also gives you the directory.

<cfdirectory
name="rs_read"
action="LIST"
directory="C:\Inetpub\fober\IMSITE8" recurse="Yes"
>

<cfdump var="#rs_read#">

When you loop through the result, you can use "listlen(directory,"/')" to determine how far to indent the files.

cheers,
fober
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 03, 2008 Dec 03, 2008
Thanks for your reply.

I've used the listlast function to get the path for each directory. I'd like to loop through the files and display the folders structure that way, is there a better way to do it?

Thanks in advance

<cfparam name="dir" default="">
<cfif dir eq "">
<cfset path = "c:\inetpub\wwwroot\documents">
<cfelse>
<cfset path = path & dir>
</cfif>
<cfdirectory
name="rs_read"
action="LIST"
directory="#path#" recurse="Yes"
>

<cfoutput query="rs_read">

<cfif type eq "dir">
<cfset dir = ListLast(directory, '\')>
<cfinclude template="doctest.cfm">
</cfif>

</cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 03, 2008 Dec 03, 2008
double post
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 03, 2008 Dec 03, 2008
I'd also like to tell which documents are in which folder, so I can hide/ show them in a div, when the parent folder is clicked. Can anyone help me do this?

I'd rather not use flash or a java applet to do this, I'd like to display the structure as html within the page.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2008 Dec 03, 2008
<cfdirectory
name="rs_read"
action="LIST"
directory="C:\Inetpub" recurse="Yes"
>

<cfset temp_tax_item= "0">
<cfset temp_tax_level= "0">


<div>
<cfoutput query="rs_read">
<cfset tax_level= listlen(directory,"\")>
<cfif tax_level GT temp_tax_level>
<ul id="tax_#temp_tax_item#" <cfif temp_tax_level GT 1>style="display:none;"</cfif>>
</cfif>
<cfif tax_level LT temp_tax_level>
<cfloop index="x" from="#temp_tax_level#" to="#tax_level+1#" step="-1">
</ul>
</cfloop>
</cfif>
<cfset temp_tax_item= temp_tax_item+1>
<li>
<cfif type is "dir">
<a href="javascript:void(0);"
onclick="toggle(#temp_tax_item#)"><strong>#name#</strong></a>
<cfelse>
<a href="?file=#name#">#name#</a>
</cfif>

<cfset temp_tax_level= tax_level>
</cfoutput>
</div>

<hr>

<script language="JavaScript">
function toggle(id){
obj=document.getElementById('tax_'+id);

if (obj.style.display != 'none')
obj.style.display= 'none';
else
obj.style.display= 'block';
}
</script>


<cfdump var="#rs_read#" expand="No">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 04, 2008 Dec 04, 2008
Thanks again for your reply.

I've set up something similar, by passing the path in the url for cfdirectory to list. I prefer your method as its more responsive, but am I right in thinking it renders the document structure as the page is loadeded so puts more demand on CF? Would this be a problem if lots of people tried to access the page at the same time?

Thanks again





<cfset rootPath = "c://inetpub/wwwroot/documents">

<cfif isDefined('url.pth')>
<cfset path=#url.pth#>
<cfelse>
<cfset path=#rootPath#>
</cfif>

<cfoutput>#path#</cfoutput>
<cfdirectory action="list" directory="#path#" name="fileList" sort="type,name">
<cfoutput>
<table cellpadding="1" cellspacing="1" align="center">
<tr >
<td style="font-weight:bold;">Name</td>
<td style="font-weight:bold;">Type</td>
<td style="font-weight:bold; text-align:right;">File Size</td>
<td style="font-weight:bold;">Last Modified</td>
</tr>
<cfloop query="fileList">
<cfset newpath = right(path,30)>
<tr style="background-color:<cfif currentRow MOD 2>##ffffff<cfelse>##ececec</cfif>;">
<td><cfif type eq "dir">
<a href="?area=documents&pth=#path#/#name#" class="dir">#name#</a>
<cfelse>
<a href="docs/#newpath#/#URLEncodedFormat(name)#" class="dir">#name# </a>
</cfif></td>
<td>#type#</td>
<td style="text-align:right;">#int(evaluate(size/1024))# KB  </td>
<td>#dateFormat(dateLastModified, 'mm/dd/yyyy')# #timeFormat(dateLastModified, 'h:mm tt')#  </td>
</tr>
</cfloop>
<tr>
</table>
</cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 04, 2008 Dec 04, 2008
Hi,
It depends.
If you have 5 folders and 50 files then it may be better to get the page to the customer once and be done with it, because it's faster and more convenient for the user. If you have 20,000 files, then it will be better to not create a view with all files at once, because it takes longer to generate the page.

The script snipped above comes from my library of "cool scripting stuff that is good to have if I need it" and it was not adjusted to what you need. "hide/ show them in a div" sounded like this was what you are looking for.

Depending on what you need, a good solution may be to combine my script with yours. Have a tree-view with just the folders based on my script, and if a users selects a folder you refresh the pages with the files in the folder (just like windows explorer). This could be done with frames, but again depending on what you need, that may be a good or bad idea.

cheers,
fober


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 05, 2008 Dec 05, 2008
LATEST
Thanks for all your helkp with this really appreciate it.

I've managed to come up with something, its a mish mash your code and my code, it seems to work well.

Thanks again
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources