How to: Extract the folder name that precedes the file name

Hi Friends,

How I could extract the folder name that precedes de file name?
I have a different files inside folder and subfolder.
I want to extract those name.

PS: It could be : one , two…four indentation of subfolder.
PS: The name of the folders does not have a rule, it can be any name.

image

Is there a way?

Maybe the solution would be to count how many “/” and backwards capture the name that is between the penultimate and last “/”. But I don’t know how to do it.

I use this node for that task. You would need to use the Path to URL node first in this case.

Much quicker than extracting by Regex.

1 Like

Hi @Felipereis50 .
You need a path to string node and can try formula

reverse(substr(reverse($cpath$), indexOfChars(reverse($cpath$), “/”, 0 )+1, (indexOfChars(reverse($cpath$), “/”, indexOfChars(reverse($cpath$), “/”, 0 )+1 )-indexOfChars(reverse($cpath$), “/”, 0 )-1)))

with a string manipulation node
folder.knwf (72.4 KB)

image

Br

1 Like

A.M.A.Z.I.N.G

Perfect.

I was trying to ask for chatpt, but answers me with Python code, but I don’t know nothing about python.

Thank you my friend.

I’ll studie your code to understand better.

Sorry to ask, but.
How did you manage to put together this formula?
Super complex.

I can’t even analyze it step by step. :grin:

Do you have any specific knowledge?

Hi, @Felipereis50 .
Nothing special.

Just one formula:

  1. Reversed the string.
  2. Found position of first and next “/”
  3. Substringed the initial string between first and second position
  4. Reversed the string again.

Happy to help :wink:
Regards
Hugo

2 Likes

Very creative my friend.
:sweat_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.