Why doesn't my program work? Is there a better way to write this?
Question R
.Python: I am trying to write a function where the program opens a directory and then lists all the files ending in .csv. Why doesn't my program work? Is there a better way to write this?
import os
location = r'C:\Users\Janelle\OneDrive\Desktop\Python_files'
counter = 0 #keep a count of all files found
csvfiles = [] #list to store all csv files found at location
otherfiles = [] #list to keep any other file that do not match the criteria
for file in os.listdir(location):
try:
if file.endswith(".csv"):
print("csv file found:\t", file)
csvfiles.append(file)
counter = counter+1
else:
otherfiles.append(file)
counter = counter+1
except Exception as e:
raise e
print("No files found here!")
print("Total files found:\t", counter)
print(csvfiles)
Full explain this question and text typing work only
We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this line

Step by step
Solved in 3 steps









