本帖最后由 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)
|