balala wrote: ↑August 28th, 2022, 7:48 pm
Sorry I thought you'll use the substitution ONLY for paths of files. My bad...
But now I'm not sure. For files I think my susbtitution does work. But what should it return for instance for the H:\Movies\TV Shows\ path? Sorry, but I didn't understand (my bad again)...
I think you have to use a two step substitution. In the first step you'll remove the last backslash (if there is any). In the second substitution, you get the needed part of the path and add back the backslash (if you want). Try this option please: Substitute="^(.*)\\$":"\1","^(.*)\\(.*)$":"\2\" (see below why is colored red the last backslash).
As you probably figured it out, the first substitution ("^(.*)\\$":"\1") is executed only if the path ends with a backslash. In this case, that last backslash is removed.
The second substitution ("^(.*)\\(.*)$":"\2\") returns the needed folder name and adds back the backslash. If you want not to add the last backslash, just remove the last character of the substitution (the red colored above).
CodeCode wrote: ↑August 28th, 2022, 8:25 pm
Now I am worried that this is a local issue with me, and the regexp will not work for other people.
One thing I have to add. The above substitution returns the name of the last folder in the path, if the path ends with a backslash, but returns the previous folder, if the path doesn't contain a backslash at the end. I tried to write my solution to work and return the last element in both cases. Definitely your solution is shorter, but are you absolutely positive there is no case when the last backslash is missing?
For instance for the H:\Movies\TV Shows\ path your solution returns TV Shows\, but for H:\Movies\TV Shows (no ending backslash), it returns Movies\
balala wrote: ↑August 28th, 2022, 8:53 pm
One thing I have to add. The above substitution returns the name of the last folder in the path, if the path ends with a backslash, but returns the previous folder, if the path doesn't contain a backslash at the end. I tried to write my solution to work and return the last element in both cases. Definitely your solution is shorter, but are you absolutely positive there is no case when the last backslash is missing?
For instance for the H:\Movies\TV Shows\ path your solution returns TV Shows\, but for H:\Movies\TV Shows (no ending backslash), it returns Movies\
Wow! Now that is awesome! Thanks for helping so much. In my view, balala's solution is the most versatile - since it allows for no backslash, yet provides it in the returned output.
CodeCode wrote: ↑August 28th, 2022, 8:58 pm
Wow! Now that is awesome! Thanks for helping so much. In my view, balala's solution is the most versatile - since it allows for no backslash, yet provides it in the returned output.