|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import os
- file_path = str(input('请输入待查找的初始目录:'))
- #查找结尾为mp3.rmvb.avi的格式
- def check(file_path):
- tempt = os.listdir(file_path)
- for each in tempt:
- #当遇到文件时,匹配
- eachpath = file_path + '/' + each
- if os.path.isfile(eachpath):
- #将文件分为文件名和扩展名
- tempt_file = os.path.splitext(eachpath)
- if tempt_file[1] in ['.mp4','.mkv','.avi','.rmvb']:
- print(eachpath)
- tempt_file_name.append(eachpath+os.linesep)
-
-
- #当遇到文件夹时,进入文件夹
- elif os.path.isdir(eachpath):
-
- check(eachpath)
- #return tempt_file_name
- #将查找后的文件地址放入新的文件中
- tempt_file_name = []
- program = os.getcwd()
- check(file_path)
- f = open('E:/python/vedioList1.txt','w',encoding='utf-8')
- f.writelines(tempt_file_name)
复制代码
为什么这个程序查找有的可以打印出来,存不到文件中去
|
|