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 : 바이트에서 /사용자/거품/데스크탑/플롯 2.docx 크기 : 출력 텍스트 파일 내부
, 방금 다음 수 110,549을하지만 말을해야 : UID를 : 501
f.write가 두 개의 인수를 이해하고 txt 파일에 기록하도록하려면 어떻게해야합니까?
많은 감사
'.write()'에 전달한 문자열에'{}'을 잊어 버렸습니다. –
고마워, 나는 그것을 덧붙였다. {} 정확히 뭐하는거야 ?? 어떻게 그 간단한 대괄호와 함께 작동합니까 ?? – BubbleMonster
'.format()'의 매개 변수에 대한 자리 표시 자입니다 ([형식 문자열 구문] (http://docs.python.org/2/library/string.html#formatstrings) 참조). –