我的程序的重点是搜索目录(由用户提供)打开目录中的文件,打开文件中的内容并在文件中的文档中查找字符串。我使用一个名为 easygui 的 GUI 来询问用户的输入。当我运行程序时,出现两个错误:
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