Error: os.listdir()
vezycash opened this issue · comments
vezycash commented
import os
files = os.listdir()
for file in files:
if file.endswith(".txt"):
print(file)
Function os.listdir() expects an argument (a folder name)
files = os.listdir("folder")
folder = the folder which contains the text files.
OR
files=os.listdir(".")
//In this case, the files have to be in the same directly as file.py
Suraj Patil commented
Actually, since pytjon3 it accepts zero arguments, if there is no argument, it lists the current directory
vezycash commented
You're right.