|
|

楼主 |
发表于 2016-3-29 03:53:26
|
显示全部楼层
伤透了心……等了2天没高手解决。百度也解决不了,google被the fucking wall挡住……结果只能自己慢慢摸索办法。- import os
- def search_file(start_dir, target) :
- os.chdir(start_dir)
- allfile = os.listdir(os.curdir)
- #print(allfile)
- for each_file in allfile:
- print(each_file)
- ext = os.path.splitext(each_file)[1]
- if ext in target :
- vedio_list.append(os.getcwd() + os.sep + each_file + os.linesep) # 使用os.sep是程序更标准
- if os.path.isdir(each_file) :
- [color=Red] try:
- search_file(each_file, target) # 递归调用
- os.chdir(os.pardir) # 递归调用后切记返回上一层目录
- except OSError as reason:
- print(reason)
- continue
- [/color]
- start_dir = 'C:\\'#input('请输入待查找的初始目录:')
- program_dir = os.getcwd()
- target = ['.mp4', '.avi', '.rmvb']
- vedio_list = []
- search_file(start_dir, target)
复制代码 |
|