|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import os
- import os.path
- def search_file(start_dir):
- os.chdir(start_dir)
- #print('kkkkkkkkkkkkkkkkkk')
- for each_file in os.listdir(os.curdir):
- file_path = os.getcwd() + os.sep + each_file + os.linesep
- extension = os.path.splitext(file_path)[1]
- if extension in ['.mp4', '.rmvb', '.avi' ]:
- empty_list.append(file_path)
-
- if os.path.isdir(each_file):
- search_file(each_file)
- os.chdir(os.pardir)
- start_dir = input('请输入待查找的初始目录:')
- empty_list = []
- program_dir = os.getcwd()
- search_file(start_dir)
- final_file = open(program_dir + os.sep + 'emptyList.txt', 'w')
- final_file.writelines(empty_list)
- final_file.close()
- final_file = open(program_dir + os.sep + 'emptyList.txt')
复制代码
函数调用也没有问题,已经都循环完了,但是题目要求把得到的路径都保存到emptyList.txt,但是打开之后总是空的txt文件。不知道哪里错了,指点指点一下,谢谢 |
|