|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import os
- def search(start_path):
- os.chdir(start_path)
- namelst = os.listdir(os.curdir)
- extension = ['.mp4','.rmvb','.avi']
- for each_file in namelst:
- if os.path.isfile(each_file):
- if os.path.splitext(each_file) in extension:
- f = open('D:\\vedioList.txt','x')
- final_path = start_path + each_file
- f.writelines(final_path)
- f.close()
- if os.path.isdir(each_file):
- search(each_file)
- os.chdir(os.pardir)
- start_path = input('请输入待查找的初始目录:')
- search(start_path)
复制代码
在运行过后没有报错也没有结果,这是为什么呢?
还有一个小问题:小甲鱼的片名能搜到嘛?
本帖最后由 jackz007 于 2021-2-6 18:33 编辑
- import os
- def search(start_path):
- pwd = os . getcwd()
- os . chdir(start_path)
- cwd = os . getcwd()
- extension = ['.mp4','.mkv' ,'.flv' , '.rmvb' , '.rm' , '.wmv' , '.avi']
- try:
- for each_file in os.listdir(os . curdir):
- if os . path . isfile(each_file):
- if os . path . splitext(each_file)[1] . lower() in extension:
- f = open('D:\\vedioList.txt','a')
- final_path = os . path . join(cwd , each_file)
- f . write(final_path + '\n')
- f . close()
- elif os . path . isdir(each_file):
- search(each_file)
- except Exception as e:
- print(e)
- os . chdir(pwd)
- start_path = input('请输入待查找的初始目录:')
- if os . path . exists('D:\\vedioList.txt') and os . path . isfile('D:\\vedioList.txt'):
- os . remove('D:\\vedioList.txt')
- search(start_path)
复制代码
|
|