How do I get the folder name in a string? for example my string would look like this: C:\Users\Administrator\Desktop\Manga\Batch\Beware the Villainess! (Digital) (1r0n)\Beware the Villainess! v01 (2024) (Digital) (1r0n).cbz I want to get the folder name so the output should be Beware the Villainess! (Digital) (1r0n)
I tried using the javascript split function but it doesn’t seem to be valid syntax in n8n
Didn’t know .at() was an option.
I always use .slice(-1)[0] and that does work.
Can also use .pop() and such. No idea why .at() isn’t working.
Correction: it is working with .at()
The \ is a special character though so it is probably not working with that, you can use \ to escape it. try \\ that should work
const path = "C:\\Users\\Administrator\\Desktop\\Manga\\Batch\\Beware the Villainess! (Digital) (1r0n)\\Beware the Villainess! v01 (2024) (Digital) (1r0n).cbz";
// Split the path into parts
const parts = path.split("\\");
// Get the second-last item (folder name)
const folderName = parts[parts.length - 2];
console.log(folderName);