get material file paths

Is there a way to get the file paths of materials?

Ok I managed to find it. It is in


bpy.data.meshes['MeshName'].uv_textures['UV Name'].data[0].image.filepath

Is there a simple way to convert a string to a bytes object?

I am trying to pack the string which is the file path and it wants it as a byte object. I tried using bytearray() and bytes(). It runs the script but I’m pretty sure it’s outputting it wrong when I write it to the file.

Furthermore I want the full path not just the relative path. I have tried using os.path.abspath(path) and it does give me a different result but it doesn’t give me what I want. I want something like C:\Users\ and so on.

This is what the script looks like atm:


for tex in obj_data.uv_textures:
                data = os.path.abspath(tex.data[0].image.filepath)
                data = struct.pack('<s',bytearray(data,'ascii'))
                out.write(data)

EDIT:


bpy.path.abspath(bpy.data.meshes['MeshName'].uv_textures['TextureName'].data[0].image.filepath)

Seems to work for getting me the full path that I want. However I still can’t figure out how to pack it in little-endian for binary output.