我需要检查两种文件的数千个目录。我将索引(idx)限制在四个以内,因为在这个范围内,需要找到两种文件,即“jpg”和“.thmb”。但是我需要if语句来要求这两种文件在目录中。if语句:
if ('.jpg' in val) and ('thmb' in val):
除非我一直通过else语句得到数据丢失的打印输出,当它不是真的时:
Data missing W:\\North2015\200\10 200001000031.jpg 0
Data missing W:\\North2015\200\10 200001000032.jpg 1
Data missing W:\\North2015\200\100 200014000001.jpg 0
Data missing W:\\North2015\200\100 200014000002.jpg 1
Data missing W:\\North2015\200\101 200014100081.jpg 2
代码如下:
def missingFileSearch():
for folder in setFinder():
for idx,val in enumerate(os.listdir(folder)):
if idx < 4:
if ('.jpg' in val) and ('thmb' in val):
pass
else:
print'Data missing',folder,val,idx
所以我想知道为什么我要通过else语句得到输出。 此外,这行代码也会挂起:
if val.endswith('.jpg') and ('thmb' in val):
print'Data is here!',folder,val,idx
这主要是我需要代码来做的。你知道吗
我会这样做:
我测试了这段代码的一个稍微修改的版本(没有
setFinder()
函数):我创建了四个带有自解释名称的测试文件夹:
然后运行函数:
相关问题 更多 >
编程相关推荐