Python全局精确模式匹配

2024-05-08 20:35:42 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我有下面的代码,我试图排除精确的字符串匹配,但它没有给出我想要的结果,例如,如果我的文件名是xyz_20200720.xlsx,下面的代码将排除xyz_20200720.xlsx,因为模式匹配中有一个“2”。总而言之,我试图忽略名称中有月末日期的文件


import glob
import os
import shutil


cleanlist = glob.glob('F://SM//Portfolio Monitoring//TABLEAU//ACTIVE PIPELINE//MONTH END PIPELINE FILES//**/*[!|31|0228|0430|0630|1130].xlsx',recursive=True)
print(cleanlist)
maxclean = max(cleanlist, key=os.path.getctime)
print(maxclean)
os.remove(maxclean)

movelist = glob.glob('F://SM//Portfolio Monitoring//TABLEAU//ACTIVE PIPELINE//DATE SPECIFIC//*') 
filetomove = max(movelist, key=os.path.getctime)

targetpath = 'F://SM//Portfolio Monitoring//TABLEAU//ACTIVE PIPELINE//MONTH END PIPELINE FILES//'

shutil.copy(filetomove, targetpath)

Tags: 代码importpipelineosxlsxglobmonitoringactive