changing filepath and creating directory in python filepath = bpy.data.filepath
directory = os.path.dirname(filepath)
path = directory + "/" + "BakedTextures_" + obj + "/" + obj + "_" + map + "Tex.png"


Trying to define a path variable while creating a folder inside my blend file directory to later use that variable for saving a baked image texture made in Blender. So far with this code I get this error:

Traceback (most recent call last):   File "D:\GOOGLE_DRIVE\WORK\3D_Work\OldWorld\Ducs_Armor\Ducs_Armor.blend\Text", line 15, in &lt;module&gt; TypeError: can only concatenate str (not "type") to str Error: Python script failed, check the message in the system console


Clearly I'm doing something wrong with my backslashes and probably something else, but I can't figure it out on my own, can you help please?
Python has useful functions built-in to handle common pathname manipulations.

import os
desired_path = os.path.join(some_existing_path, "some_folder", "some_file_name.ext")


See os.path, and see shutils for high-level file operations.

to test if a directory exists, and make it when not found):

if not os.path.exists(directory_to_test):
    os.makedirs(directory_to_test)