Nonbinary file in Python
Question:
I’m trying to look at all the items we have in a directory, and check whether there are file or directory. Sadly, all of them aren’t directory, neither a file.
import io, sys, os, json
path_input = "C:\Users\Me\AppData\Local\somewhere\"
for file in os.listdir(path_input):
print("Looking at " + file)
isFile = os.path.isfile(file) # False
isDir = os.path.isdir(file) # False
I’m pretty sure I’m missing something with how I handle file.
Answers:
I forgot to add the path in my function to properly locate the file (or the directory)
isDirectory = os.path.isdir(path_input+file)
Someone posted the solution but the post got deleted
I’m trying to look at all the items we have in a directory, and check whether there are file or directory. Sadly, all of them aren’t directory, neither a file.
import io, sys, os, json
path_input = "C:\Users\Me\AppData\Local\somewhere\"
for file in os.listdir(path_input):
print("Looking at " + file)
isFile = os.path.isfile(file) # False
isDir = os.path.isdir(file) # False
I’m pretty sure I’m missing something with how I handle file.
I forgot to add the path in my function to properly locate the file (or the directory)
isDirectory = os.path.isdir(path_input+file)
Someone posted the solution but the post got deleted