|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
环境 win10 64位 python版本3.5.3 下面是源代码
- import os
- import easygui as g
- import sys
- def get_target():
- target=[]
- while 1:
- add = g.enterbox('请输入需要检索的格式(输入s停止输入):')
- if add == 's':
- break
- elif add == None:
- exit(0)
- else:
- target.append('.'+add)
- return target
- def search_file(address,target):
- os.chdir(address)
-
- for each_file in os.listdir(os.curdir):
- ext = os.path.splitext(each_file)[1]
- if ext in target:
- file_list.append(os.getcwd()+os.sep+each_file+os.linesep)
- if os.path.isdir(each_file):
- search_file(each_file,target)
- os.chdir(os.pardir)
- file_list=[]
-
- address=g.diropenbox('请输入需要搜索的路径:')
- target=get_target()
- search_file(address,target)
- save_list_path=g.diropenbox('请输入列表保存的路径:')
- f = open(save_list_path+os.sep+'file_list2.txt','w')
- f.writelines(file_list)
- f.close
复制代码
test.txt 当做你要打开的文件,改成这样试试
- try:
- with open("test.txt","a") as f:
- f.write(file_list+"\n")
- except UnicodeEncodeError:
- with open("test.txt","a") as f:
- f.write(file_list.encode("gbk","ignore").decode("gbk")+"\n")
- except Exception as e:
- print(e)
复制代码
|
-
|