|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在指定目录内寻找 mp4 rmvb avi格式的文件并创建vediolist.txt保存所有路径
import os
file_new = open('E:\\vediolist.txt','w')
list1 = ['.mp4','.rmvb','.avi','.MP4','.RMVB','.AVI']
list2 = []
def find(dir_my,name_target):
os.chdir(dir_my)
all_file = os.listdir('.')
for each_file in all_file:
name = os.path.splitext(each_file)[1]
if name in name_target:
print(os.getcwd() + each_file)
list2.append(os.getcwd() + each_file)
elif os.path.isdir(each_file):
find(each_file,name_target)
os.chdir('..')
find('F:\\',list1)
file_new.writelines(list2)
file_new.close()
请问:为什么打印不出所有符合条件的路径,是因为代码问题还是电脑权限问题?
还有vediolist.txt 虽然创建了但是路径并没有写进去,是代码问题么?
求大神解答
你把运行结果和文件夹截图发下 
|
|