开发者

cfdirectory on a ColdFusion Mapping

开发者 https://www.devze.com 2022-12-15 18:41 出处:网络
I am trying to use CFDirectory to get a file开发者_高级运维 listing of a mapping created in ColdFusion Admin. So far I cannot get the list to populate, but if I reference the physical path the full fi

I am trying to use CFDirectory to get a file开发者_高级运维 listing of a mapping created in ColdFusion Admin. So far I cannot get the list to populate, but if I reference the physical path the full file list is displayed.

Here's the code I'm using:

<cfoutput> <cfdirectory action="list" directory="mymapping" name="test"><cfdump var="#test#"> </cfoutput>

Thanks,

Jon C.


Depending on how the mapping is set up - you may need to give it the full "virtual" path:

<cfdirectory action="list" directory="/mapping/folder" name="test">
<cfdump var="#test#">


You need to use the form /mymapping, with the / in front. And you need to use ExpandPath to expand the “virtual” directory as defined in the mapping /mymapping. That way, you end up using cfdirectory and passing in a physical directory, one that actually exists on the hard drive and not just in the ColdFusion mappings.

<cfdirectory
    name = "theQuery"
    action = "list"
    directory = "#ExpandPath("/mymapping")#"
/>


If you are setting the directory in a variable called "mymapping". It would be as follows:

<cfdirectory action="list" directory="#mymapping#" name="test">
<cfdump var="#test#"> 


Try this (not tested):

<cfset expandedPath=getDirectoryFromPath(expandPath("/mymapping/*.*")) />
<cfdirectory action="list" directory="#expandedPath#" name="dirListing" />
<cfdump var="#dirListing#" />


You didn't say which version of CF are you using, so Goyix's solution is partially correct: it works with the Railo, but not ACF.

In ACF8+ you can use the ServiceFactory to extract the real path. Code can look like this:

<cfset mapping = "/fusebox5" />

<cfset serviceFactory = createObject("java","coldfusion.server.ServiceFactory") />
<cfset mappings = serviceFactory.runtimeService.getMappings() />

<cfif StructKeyExists(mappings, mapping)>
    <cfdirectory action="list" directory="#mappings[mapping]#" name="test">
    <cfdump var="#test#">
<cfelse>
    <p>Mapping not found</p>
</cfif>

Note: used my existing FB5 mapping for the testing.

EDIT

Proposed later method with ExpandPath is much clearer. Leaving this one only as possibly useful alternative solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消