Directory for python repl?
I have a program where I want to look through a folder for data. How would I list that directory if I upload the folder to my repl?
I have a program where I want to look through a folder for data. How would I list that directory if I upload the folder to my repl?
os.listdir()
will show everything in the directory including files and directories. Docs hereIf you want files only, you could either filter this down using
os.path
Docs here:or you could use
os.walk()
(Docs here) which gives a list of directories and files separately. If you only want the top directory you can just break the first time it yieldsIf you want to put the files in a list you can use
.extend()
Docs Here@Scoder12 Good and complete answer ! Thanks ;)
@MichelleSanche2 If this post answered your question please mark it as the answer