私のプログラムのポイントは、(ユーザーが指定した)ディレクトリを検索してディレクトリ内のファイルを開き、ファイル内のものを開いて、ファイル内のドキュメント内の文字列を探すことです。easygui という GUI を使用して、ユーザーに入力を求めます。プログラムを実行すると、次の 2 つのエラーが発生します。
Traceback (most recent call last):
File "C:\Users\arya\Documents\python\findstrindir", line 11, in <module>
open(items)
IOError: [Errno 2] No such file or directory: 'm'
また、ファイルまたはディレクトリが正しくないことも 100% 確信しています'm'
これは私のコードです:
import os, easygui, sys
path = easygui.enterbox(msg='Enter Directory')
strSearch = easygui.enterbox(msg = 'Enter String to search for')
dirs = os.listdir(path)
fCount = 0
strCount = 0
for file in dirs:
fCount += 1
for items in file:
open(items)
trt = items.read()
for strSearch in trt:
strCount +=1
print "files found:", fCount