output - Python's osWalk to text file? only one line being printed -
import os searchfolder = '/users/bubble/desktop/pics' root, dirs, files in os.walk(searchfolder): file in files: pathname = os.path.join(root,file) print pathname print os.path.getsize(pathname) print f = open('/users/bubble/desktop/workfile.txt','w') f.write(pathname)
only 1 line being printed text file: /users/bubble/desktop/pics/img_2999.jpg
i want entire output printed text file (perhaps later, html file can edit pretty)
thanks
you're overwriting file in loop. open once.
import os searchfolder = '/users/bubble/desktop/pics' open('/users/bubble/desktop/workfile.txt','w') f: root, dirs, files in os.walk(searchfolder): file in files: pathname = os.path.join(root,file) print pathname print os.path.getsize(pathname) print f.write('{}\n'.format(pathname)) f.write('{}\n'.format(os.path.getsize(pathname)))
Comments
Post a Comment