-1
import os

searchFolder = '/Users/bubble/Desktop/pics'


for root, dirs, files in os.walk(searchFolder):
    for 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) 

/Users/bubble/Desktop/pics/IMG_2999.JPG の 1 行のみがテキスト ファイルに出力されます。

出力全体をテキスト ファイルに出力したい (後で、見栄えを良くするために編集できる html ファイルも)

ありがとう

4

1 に答える 1

2

ファイルをループで上書きしています。一度開きます。

import os

searchFolder = '/Users/bubble/Desktop/pics'

with open('/Users/bubble/Desktop/workfile.txt','w') as f:
    for root, dirs, files in os.walk(searchFolder):
        for 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)))
于 2013-07-22T06:54:03.333 に答える