baseNames = ["this","that","howdy","hello","anotherfile"]
testList = ["this.txt","that.txt","howdy.txt","hello.txt"]
def _validateFilesExist(self):
for basename in self.baseNames:
self.baseNameCounter+=1
self.logger.logInfo("Looking for file-> " + basename)
for filename in self.testList:
if basename in filename:
self.counter+=1
self.logger.logInfo("File was found")
#else:
# self.logger.logInfo(basename)
if self.counter != self.baseNameCounter:
raise Exception("All files not avaialble")
else:
self.logger.logInfo("All files available")
如果我取消对底部的else语句的注释,这就是输出的样子
我真的只是想让它说,文件没有找到一次明显的,如果它没有找到。只是有点不懂逻辑。顺便说一句,我不想使用检查精确匹配是,这就是为什么我使用'在'如果条件时,遍历
将两个列表都转换为set并使用minus将是更好的解决方案
diff_files = list(set(baseNames) - set(testList))
最后检查
len(diff_files)
更新1:
下面的代码是想法,它可能不是最优的
更新2:只获取不存在的文件
相关问题 更多 >
编程相关推荐