I'm trying to use os.walk in order to access all files and all subfolders within a given folder. At first, my code looks like this:
for root, dirs, files in os.walk("/home/DataScience"):
for dirName in dirs:
print dirName
However, the output of the above puts the files variable into a list-- I need it to iterate over each object within the list instead.
So I go ahead and put in an additional for loop as such:
for root, dirs, files in os.walk("/home/DataScience"):
for dirName in dirs:
for fileName in files:
print dirName
Now, however, there is no output. For some reason, it seems as if putting the additional loop makes it such that the print statement on the 4th line doesn't output properly.
My question then is this: why does this additional for loop eliminate my output?