-6
import os 

for dirname, dirnames, filenames in os.walk('# I will have a directory here'):
    for filename in filenames:
        print (os.path.join(dirname, filename))

It is meant to print the directory for some files in Python. But apart from that I know little... Thanks... There are other pages with the code but it didn't fully explain it in a 'guide for dummies' style.. So I was a little confused. Thanks for your help..:)

Ali Akbar
  • 9
  • 1
  • 6
noob96
  • 101
  • 6

1 Answers1

6

i'll give it a shot, hope this helps.

import os 
#   vvvvvvv directory name of the current position in the walk (eg, /var then /var/log then /var/log/apache2, etc)
#            vvvvvvvv list (array) of sub directories
#                      vvvvvvvvv list (array) of files
for dirname, dirnames, filenames in os.walk('# I will have a directory here'): # loops through the directories list
    for filename in filenames: #loops through the files returned by the previous for loop
      print (os.path.join(dirname, filename)) # join the directory and the filename returning something like /var/log/dmesg.log