I am trying to find the path that is located one directory up and contains a specific word. For example, the path I am trying to find here will be /whatever/path/2343blah344
oldpath = '/whatever/path/itis'
newpath = os.path.join(os.path.dirname(oldpath), '/*blah*')
When I print newpath, it only shows up as /*blah, so I’m pretty sure * did not work or this is not the right way to approach it.
Just to be clear, os.path.join works on text strings. It does not actually compare them with the underlying operating system in any sophisticated way. This is useful both for effeciency and for when you want to create paths that aren’t tied to the computer this is currently executing on.
As Burhan Khalid suggested, glob is the best way to achieve what you actually want. If you want to do it all with the os library for some reason, then you can do something like using os.walk to get all the possibilities and then filter through those.