1 Star 0 Fork 46

叫我古竣歌/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.1.12 目录树中搜索程序 827 Bytes
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-01-12 10:23 . new file
import os, sys
listonly = False
textexts = ['.py', '.pyw', '.txt', '.c', '.h']
def searcher(startdir, searchkey):
global fcount, vcount
fcount = vcount = 0
for(thisDir, dirsHere, filesHere) in os.walk(startdir):
for fname in filesHere:
fpath = os.path.join(thisDir, fname)
visitfile(fpath, searchkey)
def visitfile(fpath, searchkey):
global fcount, vcount
print(vcount + 1, '=>', fpath)
try:
if not listonly:
if os.path.splitext(fpath)[1] not in textexts:
print('Skipping', fpath)
elif searchkey in open(fpath).read():
input('%s has %s' % (fpath, searchkey))
fcount += 1
except:
print('Failed:', fpath, sys.exc_info()[0])
vcount += 1
if __name__ == '__main__':
searcher(sys.argv[1], sys.argv[2])
print('Found in %d files, visited %d' % (fcount, vcount))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/ccy920/qytang_Python.git
git@gitee.com:ccy920/qytang_Python.git
ccy920
qytang_Python
qytang_Python
master

搜索帮助