I am trying to identify all files with certain names in a folder. I am using standard code to do that looking like this:
for paths, subdirs, files in os.walk(start_dir, topdown=True):
for file in files:
print(os.path.join(paths, file))
My problem is about the output of this code in windows machine, basically dynamic parts of the path have wrong slash sign:
D:/JAJA/Projects/DAF/AIM/WEBAPP/trunk/src/main/java/ie/gov/agriculture/aim\aes\AesSheetNumberEntity.java
D:/JAJA/Projects/DAF/AIM/WEBAPP/trunk/src/main/java/ie/gov/agriculture/aim\aes\DocumentReceivedDetailEntity.java
D:/JAJA/Projects/DAF/AIM/WEBAPP/trunk/src/main/java/ie/gov/agriculture/aim\aes\DocumentReceivedEntity.java
D:/JAJA/Projects/DAF/AIM/WEBAPP/trunk/src/main/java/ie/gov/agriculture/aim\aes\DocumentTypeEntity.java
start folder which was given is:
D:/JAJA/Projects/DAF/AIM/WEBAPP/trunk/src/main/java/ie/gov/agriculture/aim
and the folder separator is unix one: "/"
while all subsequent subfolders found by os.walk function have windows slash instead: "\"
So at the end I have invalid path which cannot be used straight away. Is this a bug in python os library or what actually?
Currently I can easily replace wrong separator with the right one but I am wondering if it is the only way?