|
ColdFusion 9.0 Resources |
DirectoryListDescriptionLists the contents of on-disk or in-memory directory. Also lists the contents of the sub-directories if recurse is set to true. ReturnsContents of the directory based
on the parameter listInfo:
CategoryFunction SyntaxDirectoryList(path [,recurse] [,listInfo] [,filter] [,sort]) Parameters
UsageEnsure that you have the required permissions to run this function. ExampleThe following code dumps the contents of a directory: <h2>DirectoryList Example</h2>
<h3>Enter a directory for Listing.</h3>
<cfform action = "directoryList.cfm" method="post" preservedata="true" >
<label for="listDirectory">Directory Path: </label><cfinput type = "text" id="listDirectory" name = "listDirectory">
<br />
<label for="recurse">Recurse: </label><cfinput id="recurse" type="checkbox" value="recurse" name="recurse">
<br />
<label for="listInfo">List Info: </label>
<cfselect name="listInfo" id="listInfo">
<option value="name">name</option>
<option value="path">path</option>
<option value="query">query</option>
</cfselect>
<br />
<label for="filter">Filter: </label><cfinput id="filter" type="text" value="" name="filter">
<br/>
<input type = "submit" value="submit" name = "submit">
</cfform>
<cfif IsDefined("FORM.listDirectory")>
<cfif FORM.listDirectory is not "">
<cfset listDirectory = FORM.listDirectory>
<cfset recurse = false>
<cfif isDefined("FORM.recurse")>
<cfset recurse = true>
</cfif>
<cfset listInfo = FORM.listInfo>
<cfset filter = FORM.filter>
<cftry>
<cfset res= DirectoryList(listDirectory,recurse,listInfo,filter)>
<cfoutput><b>Content of Directory #listDirectory#: </b></cfoutput>
<cfdump var="#res#">
<cfcatch>
<b>Error Message:</b><cfoutput>#cfcatch.message#</cfoutput><br/>
<b>Error Detail:</b><cfoutput>#cfcatch.Detail#</cfoutput>
</cfcatch>
</cftry>
</cfif>
</cfif>
|