Skip to main content
Known Participant
March 10, 2010
Answered

Add Subdirectory to Path

  • March 10, 2010
  • 4 replies
  • 604 views

Hi,

I thought this would be simple.

My code

<cfset

Application.data_directory = ExpandPath("data")>

<cfif

not DirectoryExists(Application.data_directory)>

<cfdirectory action = "create" directory = "#Application.data_directory#" >

</cfif>

<cfset

Application.County_Selections_Path = GetDirectoryFromPath(Application.data_directory) & "CountySelections.json">

My results

county_selections_path=C:\ColdFusion8\wwwroot\CountySelections.json
data_directory=C:\ColdFusion8\wwwroot\data

But I really Need

county_selections_path=C:\ColdFusion8\wwwroot\data\CountySelections.json
data_directory=C:\ColdFusion8\wwwroot\data

I need to be certain I use the correct file seperator ("\") for our systems.

Suggestions?

This topic has been closed for replies.
Correct answer Adam Cameron.

I think you need to re-read the docs for getDirectoryFromPath(), specifically this bit:

Parameter

Description

path

Absolute path (drive, directory, filename, and extension)

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_36.html#1104945

--

Adam

4 replies

Fernis
Inspiring
March 16, 2010

Well, personally I think that solution is messy.

I've adoped Sean Corfield's and Ben Nadel's suggestions as best-practice, so that's still what I'd recommand.

http://corfield.org/blog/index.cfm/do/blog.entry/entry/Backslash_is_NOT_a_path_separator

--

-Fernis - http://fernis.net/ - ColdFusion Developer For Hire

March 16, 2010

Personally, I would get the correct file separator like this:

<cfset pathSeparator=createObject("java", "java.lang.System").getProperty("file.separator")/>

Joseph DeVore

http://josephdevore.com

Fernis
Inspiring
March 16, 2010

Why use backslash at all?

Forward slash is cross-compatible and works in all environments, windows too.

When dealing with paths, I always replace backslashes with forward slashes before I proceed further.

path = replace(path,"\","/","all);

--

-Fernis - http://fernis.net/ - ColdFusion Developer For Hire

Adam Cameron.Correct answer
Inspiring
March 10, 2010

I think you need to re-read the docs for getDirectoryFromPath(), specifically this bit:

Parameter

Description

path

Absolute path (drive, directory, filename, and extension)

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_36.html#1104945

--

Adam

flhtflhtAuthor
Known Participant
March 11, 2010

Thanks Adam, that's what I needed to get my head level again!