Last active
October 26, 2016 15:02
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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