2

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.

JonCav
  • 167
  • 7
  • The mapping is setup in CF Admin "Logical Path" is /mymapping and "Physical Path" is D:\home\mydomain.com\wwwroot\mystuff Neither one of the suggestions thus far have worked, the first does not apply because this is not a path set in a variable. – JonCav Jan 09 '10 at 20:12

5 Answers5

2

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#">
Goyuix
  • 23,614
  • 14
  • 84
  • 128
1

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")#"
/>
yfeldblum
  • 65,165
  • 12
  • 129
  • 169
0

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#"> 
jarofclay
  • 680
  • 4
  • 12
0

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.

Sergey Galashyn
  • 6,946
  • 2
  • 19
  • 39
0

Try this (not tested):

<cfset expandedPath=getDirectoryFromPath(expandPath("/mymapping/*.*")) />
<cfdirectory action="list" directory="#expandedPath#" name="dirListing" />
<cfdump var="#dirListing#" />
ale
  • 6,369
  • 7
  • 55
  • 65