I read this other post but none of the solutions there worked, say I have this folder structure:
main.py
src\
s1\
dummy.txt
s2\
dummy.txt
And this code:
import os
for filename in os.listdir('.'):
isdir=os.path.isdir(filename)
print('%s : %s'%(filename,isdir))
When I run it with .
as the parameter of listdir()
it works, it shows src : True
and main.py : False
which is right because there is a folder called src
but when I try running it with src
as parameter this is the output I get: s2 : False
and s1 : False
, it should return true because there are also two folders inside src which are called s1 and s2.
I can't really use escaped backslashes as the folder path is going to be provided by other functions so it's all dynamic, but I've tried dynamically replacing the backslashes to forward slashes and it also didn't work.
I created this Repl to show exactly what happens.