Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialleakedmemory
12,178 PointsDo I Not Understand the Problem Statement?
- Read all the files names in a directory.
- Test that all the provided file names are in that directory.
So, I get a list of files in the directory and then make sure each file name is in that list.
I wonder what I'm missing here. I also tried using os.walk to get all files in all sub-directories.
Thanks for any help!
import os
def dir_contains(path, file_names):
files = [f.name for f in os.scandir(path) if f.is_file()]
for f in file_names:
if f not in files:
retun False
return True
1 Answer
Max Madubuike
Full Stack JavaScript Techdegree Student 8,258 PointsDid you create a test to ensure that the files in the directory actually exist?
leakedmemory
12,178 Pointsleakedmemory
12,178 PointsEdited code passes: I didn't type the return keyword correctly.