Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add Subdirectory to Path

New Here ,
Mar 10, 2010 Mar 10, 2010

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?

TOPICS
Getting started
562
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 10, 2010 Mar 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

Translate
LEGEND ,
Mar 10, 2010 Mar 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 10, 2010 Mar 10, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 15, 2010 Mar 15, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 15, 2010 Mar 15, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 15, 2010 Mar 15, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources