3
$\begingroup$

I'm trying to find the directory where an image file for a slot texture is located. It works fine for most paths, but when the paths are qualified with .. (to back up a directory) it will then crash when I try to use os.listdir.

So, for example, this works if the image path is straightforward (Windows only -- not interested in any other OS since this only runs for Windows):

V:\somepath\geo\this image.png

mypath = mtex_slot.texture.image.filepath
for filename in os.listdir(mypath)

but this fails if the image location includes backpathing:

V:\somepath\geo\..\textures\this image.png

where the directory structure where the file is located is: V:\somepath\textures\this image.png

The image location works in Blender with back paths -- which is to say specifying it that way in the image path will correctly resolve. But it will not resolve in the os.listdir function. So is there a way to read this in Python, or must I parse it myself by writing my own backpath function?

$\endgroup$

1 Answer 1

4
$\begingroup$

Crap -- I have GOT to stop asking questions until I spend more hours looking for an answer.

Sorry, folks, but os.path.realpath(mypath) works for me. Sigh. Nothing to see here, move along.

$\endgroup$
1
  • $\begingroup$ You may also find bpy.path.abspath() of interest, it will resolve blenders use of // to start at the project dir. $\endgroup$
    – sambler
    Jun 23, 2018 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .