import os
with open('output.txt', 'w') as a:
    for path, subdirs, files in os.walk('C:\\Users\\user\\Desktop\\Test_Py'):
        for filename in files:
            f = os.path.join(path, filename)
a.write(str(f) + os.linesep)
Python: List all the file names in a directory and its subdirectories and then print the results in a txt file