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

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -