Hey everyone, I am thinking of putting in a featur...
# lucee
g
Hey everyone, I am thinking of putting in a feature request for getting the parent directory. at the moment I have this code in my Application.cfc to create the mappings.
Copy code
this.currentPath = getDirectoryFromPath(getCurrentTemplatePath());
this.delim = find("/", this.currentPath) ? "/" : "\";
this.basePath = listDeleteAt(this.currentPath, listLen(this.currentPath, this.delim), this.delim);
this.mappings["/coldspring"] = "#this.basePath#/cfmapping/coldspring/";
Which is fine and works great... But I have just installed testBox and it comes with its own Application.cfc - which I know I can do without... I don't need it - but as a default its application.cfc comes with similar code for creating the mappings... again all fine - but it is off by one directory. The very short version of all this is I would like to propose a new function for getting the "parent" directory - which would effectively just be - in CFML
Copy code
listDeleteAt(this.currentPath, listLen(this.currentPath, this.delim), this.delim);
Thoughts?
d
I would thnk more useful would be a
listPop()
function. I was always a bit surprised that ACF added
listRest()
without a corresponding function to return a list without the last element. So:
Copy code
listPop(this.currentPath, this.delim);
Would be the same as:
Copy code
listDeleteAt(this.currentPath, listLen(this.currentPath, this.delim), this.delim);
At least then you have a generic function for just returning a list without the last item. It's not specific for directories.
👍 2
z
typos fixed 🙃
a
@dswitzer careful.
pop
would return the element, not the new list. Was gonna suggest that until I noticed that. But I would def go for an idiomatic approach to removing an item from a list as a generic treatment of this, more than I would get behind another path-monkeying function.
Kotlin has a
dropLast
function (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/drop-last.html). Python has a
del
statement which deletes the
n
th element from a list, but isn't a function so isn't quite the same. Can't see an equiv in PHP, Java, C#, Ruby However Kotlin's
dropLast
(from the back) is paired with
drop
(from the front).
g
@Adam Cameron I agree - the more generic version would be better! So we need a list version of array.pop - then? For the moment I can keep on with what I am doing - or listToArray and use "pop" @zackster for the docs - how about?
Copy code
moreMoreNumbers = [ ];
dump( ArrayPop( moreMoreNumbers, 44 ) ); // Outputs 44
dump( moreMoreNumbers ); // Outputs []