import os
with open(os.path.expanduser('~/matches.txt'), 'w') as f:
    for dirpath, dirnames, filenames in os.walk(os.path.expanduser('~/x/y')):
        for x in (dirnames + filenames):
            f.write('{}\n'.format(os.path.join(dirpath, x)))
equivalent to the find coreutil command in python 3 for recursively returning all files and folders in a directory structure?