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.
As per the docs- ColdFusion Help | cffile action = "read"
If you want to use a relative path you can use ColdFusion Help | ExpandPath to pass the relative path and get the absolute path.
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.
You can just do something like:
<cfset absPath = expandPath("/kb/article/Groups.json")>
<cfset groupData = deserializeJSON(fileread(absPath))
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.
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.
Thank you so much for the help. I got it.