Coast Line
asked on
file manager unable to see the files under the folders
creating a file manager in coldfusion and having some troubling viewing the directory contents
Here is the code I am using
jqueryFile.cfm
This is the function
using this jquery plugin
but somehow i am not able to browse the files, it is showing me like this:
http://prntscr.com/p0btt6
Here is the code I am using
<div class="col-sm-3 sidenav">
<div class="panel panel-default">
<div class="panel-heading">Folders</div>
<div class="panel-body">
<div id="drivestree"></div>
</div>
</div>
jqueryFile.cfm
<cfset drives = {}>
<cfset alphabet = "abcdefghijklmnopqrstuvwxyz">
<cfloop from="1" to="#len(alphabet)#" index="i">
<cftry>
<cfset thisdrive = mid(alphabet,i,1)>
<cfset checkDrive = Application.fileManager.manager.getDirectories(path=thisdrive & ":\",addHasDirs=true,hidehidden=true)>
<cfif checkDrive.directories.recordcount>
<cfset drives[thisdrive] = checkDrive>
</cfif>
<cfcatch><!--- failed Silently ---></cfcatch>
</cftry>
</cfloop>
<ul class="jqueryFileTree"<!--- style="display: none;" --->>
<cfif not structisempty(drives)>
<cfset drivelist = listsort(structkeylist(drives),"text","asc")>
<cfoutput>
<cfloop list="#drivelist#" item="d">
<cftry>
<cfif drives[d].directories.recordcount>
<li class="directory collapsed"><a href="##" rel="#URLDecode(d)#">#d#:\</a>
<ul>
<cfloop query="drives[d].directories">
<cfif type eq "dir">
<li class="directory collapsed"><a href="##" rel="#URLDecode(name)#/">#name#</a></li>
<cfelseif type eq "file">
<li class="file ext_#listLast(name,'.')#"><a href="##" rel="#URLDecode(name)#">#name# (#round(size/1024)#KB)</a></li>
</cfif>
</cfloop>
</ul>
</li>
</cfif>
<cfcatch><!--- be silent ---></cfcatch>
</cftry>
</cfloop>
</cfoutput>
</cfif>
</ul>
<ul class="jqueryFileTree">
<cfif not structisempty(drives)>
<cfoutput>
<cfloop collection="#drives#" item="d">
<cftry>
<cfif drives[d].directories.recordcount>
<li class="directory collapsed"><a href="##" rel="#URLDecode(d)#">#d#:\</a></li>
<cfloop query="drives[d].directories">
<cfif type eq "dir">
<li class="directory collapsed"><a href="##" rel="#URLDecode(name)#/">#name#</a></li>
<cfelseif type eq "file">
<li class="file ext_#listLast(name,'.')#"><a href="##" rel="#URLDecode(name)#">#name# (#round(size/1024)#KB)</a></li>
</cfif>
</cfloop>
</cfif>
<cfcatch><!--- be silent ---></cfcatch>
</cftry>
</cfloop>
</cfoutput>
</cfif>
</ul>
This is the function
<cffunction name="getDirectories" output="false" description="Returns the list of directories in given path - starting from root path" access="public" returntype="struct">
<cfargument name="path" required="false" type="string" default=""/>
<cfargument name="addHasDirs" required="false" type="boolean" default="true"/>
<cfargument name="hidehidden" required="false" default="0">
<cfset var dirs = ""/>
<cfset var allElements = ""/>
<cfset var subdirs = ""/>
<cfset var basedir = ""/>
<cfset var result = structnew()/>
<cfset result["status"] = true />
<cfset var fileSeparator = "\">
<cfif not findnocase("windows",server.os.name)>
<cfset fileSeparator = "/">
</cfif>
<cftry>
<cfset basedir = arguments.path />
<cfdirectory action="LIST" directory="#basedir#" name="allElements">
<cfquery name="dirs" dbtype="query">
SELECT *, '#arguments.path##fileSeparator#' + Name as Path <cfif arguments.addHasDirs>, 0 as hasDirs</cfif>
FROM allElements
WHERE type = 'Dir'
<cfif arguments.hidehidden eq 1>
and attributes != 'H'
</cfif>
</cfquery>
<cfif arguments.addHasDirs>
<!--- recurse once to add whether it has sub dirs --->
<cfoutput query="dirs">
<cfset subdirs = getDirectories(dirs.Path,false).directories />
<cfif subdirs.recordcount>
<cfset querysetcell(dirs,"hasDirs",1,currentrow)/>
</cfif>
</cfoutput>
</cfif>
<cfset result["message"] = dirs.recordcount & " sub-directories found" />
<cfset result["directories"] = dirs/>
<cfcatch type="Any">
<cfset result["directories"] = queryNew("Name") />
<cfset result["status"] = false />
<cfset result["message"] = cfcatch.message />
</cfcatch>
</cftry>
<cfreturn result />
</cffunction>
using this jquery plugin
// jQuery File Tree Plugin
//
// Version 1.01
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 24 March 2008
//
// Visit http://abeautifulsite.net/notebook.php?article=58 for more information
//
// Usage: $('.fileTreeDemo').fileTree( options, callback )
//
// Options: root - root folder to display; default = /
// script - location of the serverside AJAX file to use; default = jqueryFileTree.php
// folderEvent - event to trigger expand/collapse; default = click
// expandSpeed - default = 500 (ms); use -1 for no animation
// collapseSpeed - default = 500 (ms); use -1 for no animation
// expandEasing - easing function to use on expand (optional)
// collapseEasing - easing function to use on collapse (optional)
// multiFolder - whether or not to limit the browser to one subfolder at a time
// loadMessage - Message to display while initial tree loads (can be HTML)
//
// History:
but somehow i am not able to browse the files, it is showing me like this:
http://prntscr.com/p0btt6
ASKER
that is working on my project, so i think i can live with that as of now, Thanks for the suggestion, will fix that later, but my original question is more involved with the coldfusion code
WHERE type = 'Dir'
You can't see files because the function only returns directories.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
may I suggest you to go for another well know plugin : https://www.jstree.com/