在GLOB中查找以文件名为变量的Find [英] find find with file name as variable in glob
本文介绍了在GLOB中查找以文件名为变量的Find的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文件名类似于:Storm.abc.ibtras_all.v03r10.csv。其中ABC对于每个文件是不同的。
我有一个要删除的文件的ABC部分(即tmp2)的列表。我的想法是以文件名为变量遍历上面的列表,并将其传递给GLOB以获取匹配的文件名,然后将其删除
import glob
for i in range(len(tmp2)):
name=tmp2[i]
files=glob.glob('*.name.*')
os.remove(files)
我显然不工作。请帮助处理lob.lobb(‘.name.’)
推荐答案
这应该会有帮助。
import glob
import os
path = "YourPath"
for i in tmp2: #Iterate Your List
files=glob.glob('*.{}.*'.format(i)) #Check for files
for file in files:
fPath = os.path.join(path, file) #Form full path to file
os.remove(fPath) #Remove
这篇关于在GLOB中查找以文件名为变量的Find的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文