Skip to content

Instantly share code, notes, and snippets.

@tommyready
Last active October 26, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyready/94e848e798de8deab759fdebc8e8f9b8 to your computer and use it in GitHub Desktop.
Save tommyready/94e848e798de8deab759fdebc8e8f9b8 to your computer and use it in GitHub Desktop.
Coldfusion CFSCRIPT Function to Combine Array of Paths (Strings) into a Path (String)
<cfscript>
public string function combinePaths(required array paths) {
var fullPath = "";
for(var p=1; p <= ArrayLen(paths); p++) {
fullPath &= paths[p];
if(Right(paths[p],1) == "\") continue; // Continue to Next iteration if \ is already there
if(len((trim(GetFileFromPath(paths[p]) == 0)))) break; // Exit Loop on File Found // File should be last element in array
fullPath &= "\";
}
return fullPath;
}
LOCAL.myPaths = ["C:\","Reports","#dateFormat(now(),'ddmmYYYY')#","myreport.txt"];
writeDump( combinePaths(myPaths) ); // Outputs C:\Reports\10262016\myreport.txt
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment