1

# -*- coding: cp936 -*-
from Tkinter import *
import Tkinter
import os

# 目的:查找一个目录下的包含指定字符串的文件

def my_find(dir_name, find_str, results):
    myfiles = os.listdir(dir_name)
    for myfile in myfiles:
        file_name = dir_name + "//" + myfile
       
        if os.path.isfile(file_name):
            f = open(file_name, 'r')
            filer = f.read()
            if(find_str in filer):
                results.append(file_name)
            f.close()
        elif os.path.isdir(file_name):
            my_find(file_name, find_str, results)
    return results

def find():
    dir_name = e.get()
    find_str = e2.get()
    results = []
    my_find(dir_name, find_str, results)
    myresult = ''
    for result in results:
        myresult = myresult + result + '/n'
    edit1.insert(END, myresult)
   
   
root = Tk()

L1 = Label(root, text ='Please input the dir you want to find').pack()
e = StringVar()
entry = Entry(root,textvariable = e, width = 60)
entry.pack()

L2 = Label(root, text ='Please input the sting you want to find').pack()
e2 = StringVar()
entry2 = Entry(root,textvariable = e2, width = 60)
entry2.pack()

Button(root,text = 'Find',command = find).pack()

edit1 = Tkinter.Text(root,
                     selectbackground = 'red',
                     selectforeground = 'gray')
edit1.pack()

root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值