Why doesn't my program work? Is there a better way to write this?

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

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

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Software products
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage