import os
import shutil
initial_file_path = r'C:\Users\python_Mooc\initial_file'
move_to_path = r'C:\Users\python_Mooc\file_move_exp'
filelist = os.listdir(initial_file_path)
for files in filelist:
filename1 = os.path.splitext(files)[1]#文件后缀
filename0 = os.path.splitext(files)[0]#读取文件名
list_name = list(filename0)
list_required_name = list('coco_')
if(filename1 == '.txt')&(list_name[0:3] == list('res')): #后缀是.TXT,而且首字母是‘res’才能进行操作。
[1:]是搜索后两个,反转是[::-1]或者,number.reverse()从1234变到4321
despath = initial_file_path + '\\' +filename0+ '.txt '# .txt
shutil.move(despath, move_to_path) #一个文件移动到另一个文件夹
else:
continue