Jun-21-2021, 09:06 PM
Greetings!
I'm having a hard time justifying why I would use pathlib libraries instead of os.path.
It is not intuitive and I have a hell of a time trying to use it.
Here is an example, I have a directory with 3 Subdirs and 6 files.
I'm trying to test if an item is a file or directory.
both prints are the same.
When I add 'If' to test for Dir/File :
Thank you.
I'm having a hard time justifying why I would use pathlib libraries instead of os.path.
It is not intuitive and I have a hell of a time trying to use it.
Here is an example, I have a directory with 3 Subdirs and 6 files.
I'm trying to test if an item is a file or directory.
mydir = 'c:\\02'
for esb in os.listdir(mydir) :
print (esb)
dr = pathlib.Path(esb)
print (dr)regardless if I use 'pathlib.Path" or 'pathlib.PurePath'both prints are the same.
When I add 'If' to test for Dir/File :
mydir = 'c:\\02'
for esb in os.listdir(mydir) :
#print (esb)
dr = pathlib.Path(esb)
#print (dr)
item = dr.is_file()
if item :
print(f" File")
else :
print(f" Directory")It prints all 9 items are directories.
Thank you.
