I am having a problem with a simple piece of code, which run on both OSX and Windows. I am using Python 3.7.9.
All I am doing is to chain a path to a filename; I read a directory content, then create the full path to open this file
The path is relative; I run the python script in the same directory where images_to_rename
is located
from os import path, listdir
# Dir where the images are
assets = "images_to_rename"
# create a list of files in that dir
filelist = listdir(assets)
for file in filelist:
# join path and file name
joined_name = path.join(assets, file)
print(joined_name)
let's say that the folder has panorama.png
and house.png
. When I print on Windows, I get images_to_rename\\panorama.png
, which is wrong, since it should be images_to_rename\panorama.png
. Not sure what is the point to use path.join
if it cannot correctly use the same code on win and OSX.
I can work around by replacing \\
with \
with a replace when I call path.join
, but I was hoping to avoid that using path join. Am I missing something?