#!/usr/bin/env python# coding: utf-8import shutil
import os
defget_all_path(open_file_path):
rootdir = open_file_path
path_list =[]
list1 = os.listdir(rootdir)# 列出文件夹下所有的目录与文件for i inrange(0,len(list1)):
com_path = os.path.join(rootdir, list1[i])#print(com_path)if os.path.isfile(com_path):
path_list.append(com_path)if os.path.isdir(com_path):
path_list.extend(get_all_path(com_path))#print(path_list)return path_list
# get all file path under the given folderdefunique_postfix(raw_list):
p =[]
oo =[]for i in raw_list:
m = os.path.splitext(i)
p.append(m[1])
mm =tuple(set(p))for i in mm:
oo.append(i)return oo
defvideotype_in_given(all_suffix):
normal_with_point =['.avi','.mov','.rmvb','.mp4','.mpeg','.asf','.wmv','.navi','.3pg','.mkv','.flv','.f4v']
vdolist =[]for i in all_suffix:if i in normal_with_point:
vdolist.append(i)return vdolist
defshelter_to_given(all_suffix,needed_tpye_list):#needed_type_list are like['.xlsx','.txt']
needed =[]for i in all_suffix:if i in needed_tpye_list:
needed.append(i)return needed
defselect_given_appedx(all_file_path,appdx):
hh =[]for i in all_file_path:for a in appdx:if a in i:
hh.append(i)return hh
defmovfile(file_path_list,to_path):for i in file_path_list:
shutil.move(i,to_path)############################################defmove_needed_postfix_file(big_path,shelter_list,to_the_path):
allorgpath = get_all_path(big_path)
alluniqtype = unique_postfix(allorgpath)
needtype = shelter_to_given(alluniqtype,shelter_list)
all_file_path_after_selected = select_given_appedx(allorgpath,needtype)
movfile(all_file_path_after_selected,to_the_path)#### move_needed_postfix_file(需要处理的总目录,所需要的类型的列表要加点,移动的目标文件夹路径)