for path, subdirs, files in os.walk('C:\\temp'):
    for filename in files:
        a.write(filename + os.linesep)
Python: List all the file names in a directory and its subdirectories and then print the results in a txt file