Lets say I've got the following directory structure:
base/ | +-- app | | | +-- main | | | +-- sub | | | +-- first | | | | | +-- tib1.ear | | \-- tib1.xml | | | \-- second | | | +-- tib2.ear | \-- tib2.xml
One of the relative paths to an
ear file would be
base/app/main/sub/first/tib1.ear, how could I extract the substrings for:
- The file,
- The sub-directory after
base/app/but not including the file, that being
All of the directory names are dynamically generated, so I don't know them beyond
base/app/, and therefore cannot simply use the lengths of the known sub-strings and use
cut to truncate them; but I see how it could be possible once the filenames are known. I just feel like there's an easier way than cutting and joining a bunch of strings based on the length of other results.
I remember seeing some regular expression magic for something similar to this. It dealt with splitting and joining the substrings with backslashes, but sadly, I don't remember how they did it or where I saw it on here to look it up again.