Read all files in a folder and also the filenames in python?
Question: How to read all files and also the filenames? I am using MAC so is there any
there a different way to give path on MAC in Python?


Answer: Maybe something like this? Or os.listdir() is simpler if you don't need
recursion.

Even on Windows, Python abstracts away the differences between operating
systems if you use it well.

    
    
    #!/usr/local/cpython-3.3/bin/python
    
    import os
    
    def main():
        for root, dirs, files in os.walk('/home/dstromberg/src/outside-questions'):
            for directory in dirs:
                print('directory', os.path.join(root, directory))
            for file_ in files:
                print('file', os.path.join(root, file_))
    
    main()
    

See <http://docs.python.org/3/library/os.html> for more info.

