|Welcome to CS1315. Click on the python to add comments.|
|This page removed for FERPA compliance|
Fall 2006 Midterm 2 Review: Modules
for file in os.listdir():
|You need to take in directory as a parameter and then search for the files in that directory. Also, your 'if' conditions should check whether the extensions are capitalized or not. -Bobby Mathew|
|It looks to me like your taking care of capitalization with file.lower(), but do you need to indent your if statements after file.lower()? Student1919|
why do you need to include count = 0?
|The question is asking you to count the number of files. You need a seperate variable to keep track of it since there's no easier way of doing it. So, we're making a variable called count. We're giving it the value 0 so that it starts counting correctly. If you don't put that statement at all, it will give you an error saying that the variable is not defined or something. -Bobby Mathew|
what is os?
|os is a module in JES - stands for Operating System. It contains a list of functions which deal with the files/folders on your computer. The only function you need to know is os.listdir(directory) -Bobby Mathew|
for file in os.listdir(dir):
Why do I get the error "An error occurred while making an operating system call."?
|It works fine on my computer. Make sure you used pickAFolder() to input your directory or have a right path to the folder. - Bobby Mathew|
what is the file.lower mean?
BTW, there is a small mistake still in the code above. file.lower() returns a value that is equal to the string "file" turned into lower case. It does not change the string "file" into lower case. That string stays the same. So the line should really be something like
|It changes the entire filename to lowercase letters. Its being done here so that you don't have to search for uppercase extensions like how the question asks. You can also use 2 REMOVED 'if' conditions and avoid doing file.lower. - Bobby Mathew|
name = file.lower()
Link to this Page