coldfusionrelative-pathcoldfusion-10cffile

How to specify a relative in CFFile?


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.


Solution

  • Use the function expandPath() for this.

    expandPath('../path/to/file') returns the full server path to that file.