This is the path of my json file: https://devbox.mysite.com/search/KOGroups.json But instead of using cfhttp, I like to use cfifle with read action. I don't know how to turn this path into a relative path for cffile. I've read about this ColdFusion Read File article and it looks like they use absolute path in their example. I've tried Ben Nadel's "Relative File Paths Work In A ColdFusion File System" article but the code that he provides for getting the parent directory is not working for me. All I need is to turn this path, https://devbox.mysite.com/search/, into cffile tag so I can read the .json file.
Asked
Active
Viewed 908 times
2 Answers
2
Use the function expandPath() for this.
expandPath('../path/to/file')
returns the full server path to that file.

Adrian J. Moreno
- 14,350
- 1
- 37
- 44
-
I used the expandPath to find the path and I then I used that in the fileread('../path/to/file'), it gave me the following error: Error in custom script module (/devboxbox15/customcf/knowledge/KO-articleDetail.cfm) An error occurred when performing a file operation read on file /commonspot$/DEVELOPMENT/devbox.mysite.com/kb/KOGroups.json. The cause of this exception was: java.io.FileNotFoundException: \commonspot$\DEVELOPMENT\devbox.mysite.com\kb\KOGroups.json (The system cannot find the path specified). – 2myCharlie Mar 09 '16 at 13:57
-
Here's the code that I used:
– 2myCharlie Mar 09 '16 at 13:58 -
Okay, I got it working now. Instead of putting expandPath('../path/to/file'), I tried expandPath('file') and use that whole path and it works. Many thanks for the help though. – 2myCharlie Mar 10 '16 at 14:57
0
Looks like BKBK over in Adob coldfusion forum answered my question with the following:
<cfset koGroupsJSON = fileRead("https://devbox.mysite.com/search/KOGroups.json")>

2myCharlie
- 1,587
- 2
- 21
- 35
-
But since fileread still points to "https" for its path instead of a relative path, is there any security advantage of cfhttp over cffile fileread? – 2myCharlie Mar 07 '16 at 19:57
-
2Hang on... this file you're reading is on your server's file system, yes? You should not be using an HTTP req to read it, which you are still doing if you give it a URL rather than a path. Can you clarify? – Adam Cameron Mar 07 '16 at 20:27
-
Yes, that's my confusion when BKBK suggested it to me because if I'm still using HTTP then why am I using cfile fileread. The file is on our shared drive. In this case, it's under the /search/ folder of the site. – 2myCharlie Mar 08 '16 at 16:22
-
*...on our shared drive* Hm... is it on the *same* sever as the site OR is it on a shared drive, ie UNC path to another machine? If it is the latter, the account the CF service is running under must have access to it (assuming windows o/s). – Leigh Mar 08 '16 at 20:04
-
It is "UNC path to another machine" and the account does have access to it. My problem is when I use the CFfile fileread, it failed to find the file if I did not specify an absolutely path. – 2myCharlie Mar 08 '16 at 20:50