Is CFFILE read uses only absolute path or relative path too?

Engaged ,
Mar 11, 2016 Mar 11, 2016

Copy link to clipboard

Copied

I'm using cffile read to access to my json file. I like to know if cffile only uses absolute path or relative too? If I tried to use relative path, it kept giving me errors about file not exist.

Views

419

Likes

Translate

Translate

Report

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

Advocate , Mar 11, 2016 Mar 11, 2016
Read what I posted about the documentation. cffile read has to be an absolute path. If you use a relative path its relative to the CF temp folder:
If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function.
There is no relative path relative to your web files. IF you just put a relative path in, it will be looking in CFs temp folder for the file.

Likes

Translate

Translate
Advocate ,
Mar 11, 2016 Mar 11, 2016

Copy link to clipboard

Copied

As per the docs- ColdFusion Help | cffile action = "read"

Pathname of the file to read.
If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by theGetTempDirectory function.

If you want to use a relative path you can use ColdFusion Help | ExpandPath to pass the relative path and get the absolute path.

Likes

Translate

Translate

Report

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
Engaged ,
Mar 11, 2016 Mar 11, 2016

Copy link to clipboard

Copied

Thanks for the help. This is the code I have that is working.

<cfset groupData = deserializeJSON(fileread("\\commonspotshare.mysite.com\commonspot$\DEVELOPMENT\devbox.mysite.com\kb\article\Groups.json")) />

However, I believed this is an absolute path. I've tried the following and it's not working. The location of the display page is https://devbox.mysite.com/kb/article/index.cfm?title=test-article and the script that runs in the background to query the content are in the https://devbox.mysite.com/customcf/knowledge/knowledge.cfm but the Groups.json is the https://devbox.mysite.com/kb/article/ folder. So, that is why I'm confused as to "relative" to what. The path relative to the display page, knowledge.cfm script page, or the actual Groups.json file? I tried the following with relative to the actual groups.json file and display or index.cfm page but it's not working.

<cfset groupData = deserializeJSON(fileread("Groups.json")) />

Got this error for the above line.

The cause of this exception was: java.io.FileNotFoundException.

Likes

Translate

Translate

Report

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
Advocate ,
Mar 11, 2016 Mar 11, 2016

Copy link to clipboard

Copied

You can just do something like:

<cfset absPath = expandPath("/kb/article/Groups.json")>

<cfset groupData = deserializeJSON(fileread(absPath))

Likes

Translate

Translate

Report

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
Engaged ,
Mar 11, 2016 Mar 11, 2016

Copy link to clipboard

Copied

Okay, that works but it's not "technically" relative path. It's still using absolutely path. So back the question, if cffile read is able to use relative path, in ColdFusion, what is it "relative" to? By the way, many thanks for that code. It's much better than what I had.

Likes

Translate

Translate

Report

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
Advocate ,
Mar 11, 2016 Mar 11, 2016

Copy link to clipboard

Copied

Read what I posted about the documentation. cffile read has to be an absolute path. If you use a relative path its relative to the CF temp folder:

If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function.

There is no relative path relative to your web files. IF you just put a relative path in, it will be looking in CFs temp folder for the file.

Likes

Translate

Translate

Report

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
Engaged ,
Mar 15, 2016 Mar 15, 2016

Copy link to clipboard

Copied

LATEST

Thank you so much for the help. I got it.

Likes

Translate

Translate

Report

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