import os
from os import stat
from pwd import getpwuid
searchFolder = raw_input("Type in the directory you wish to search e.g \n /Users/bubble/Desktop/ \n\n\n")
resultsTxtLocation = raw_input("FIBS saves the results in a txt file. Where would you like to save results.txt? \nMust look like this: /users/bubble/desktop/workfile.txt \n\n\n")
with open(resultsTxtLocation,'w') as f:
f.write('You searched the following directory: \n' + searchFolder + '\n\n\n')
f.write('Results for custom search: \n\n\n')
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
print stat(searchFolder).st_uid
print getpwuid(stat(searchFolder).st_uid).pw_name
f.write('UID: \n'.format(stat(searchFolder).st_uid))
f.write('{}\n'.format(pathName))
f.write('Size in Bytes: {}\n\n'.format(os.path.getsize(pathName)))
我在这条线上遇到了麻烦:
f.write('UID: \n'.format(stat(searchFolder).st_uid))
我不知道 '{}\n'.format 是做什么的,但有人在上一个问题中提出了建议,所以我认为它可以在这里工作,但它没有。
在输出文本文件中,我得到以下内容:
UID:/Users/bubble/Desktop/Plot 2.docx 字节大小:110549
但它应该说:UID:501
如何让 f.write 理解两个参数并将其写入 txt 文件?
非常感谢