Is there any way to extract the file name from a file path, and add ", " (that’s comma,space) to it? I’m using this to track a list of picture-names that someone has selected using the Concatenate IA, and write it to one cell in Excel.
Currently I have a work around that is working (thanks to @Seb as always), but I’m hoping for something a little cleaner.
An example is this:
INPUT: D:\IntuiFace\MedMtgImages-PhotoSelector\Files\InterfaceAssets\FileSystemBrowsingJS\Images\18ADA_00001.jpg
DESIRED OUTPUT: 18ADA_00001.jpg,
It’s possible the number of characters in the file name could vary depending on the file. I was hoping there’d be a way to extract it by a delimiter, but there isn’t currently a selection for that type of slash “\”.
I couldn’t resist to answer you tonight on this one, since you’ll see as easy it can be, when you know how to write a little JavaScript
Here’s the code for your converter:
INPUT.substring(INPUT.lastIndexOf("\\")+1)
It basically finds the last index of the \ character in the INPUT string (still need to escape this special character, thus the \ in the code) and returns what’s after this index, +1 not to have the \ in the returned string.
Give it a try and confirm me it does what you were looking for
You’re awesome! I’ll give it a try and report back. Is there a way to build in a comma and a space after the last character too? That way it’ll look like a nice list when it gets written to the excel cell.
Would I just add ", " to it?
Quick explanation: the split command will break down the line into an array of elements, using “\” as separator. folder[X] will display the Xth element of this array and I use folders.length-2 to target the 2nd before the end in this array.
That’s a cool effect, @Promultis. I’d love to use that in IF someday. Thanks for sharing.
@Seb, I actually bought a beginners course some time ago, (on Udemy) but IF is keeping me too busy to go through the course! Haha, maybe that’s a good thing?
Adding another converter trick, this time it will help you calculate the number of days between a given date and current day.
In this example, I have dates stored in Excel, formatted as string like this dd/MM/YYYY
Then, I’m using this converter on a binding to this date
var date1 = new Date(INPUT);
var date2 = new Date();
var difference = date1.getTime() - date2.getTime();
var days = Math.ceil(difference / (1000 * 3600 * 24));
if (days>0) {
"Today, it's \n" + days + " days until " + INPUT
} else {
"Today, it's \n" + days*(-1) + " days since " + INPUT
}
Please note that, according to your locale date format, you may need to tweak your initial date value.
For more, please check Date object javascript documentation.