我试图忽略某个目录及其中特定路径中的文件,这是我的代码
x = open(wbCMD, 'a')
x.write('set path="C:\Program Files\WinRAR\";%path% c:/Program Files/WinRAR/\n')
x.write('Rar.exe a -r "Backup.rar" -m5 -ep1')
chkdict = {}
setdef = chkdict.setdefault
for root, dirs, files in os.walk(foldername):
if ignoreddirs in dirs:
continue
for file in files:
ext = path.splitext(file)[1]
if ext in ignored:
continue
if not ext in chkdict:
print("%s" % setdef(ext,ext))
x.write(" *%s" % setdef(ext,ext))
x.write(" *makefile *Depend *readme\npause")
x.close
del chkdict
ignoreddirs数组看起来像这样
ignoreddirs = ["bin"]
答案 0 :(得分:0)
dirs
和ignoreddirs
都是字符串列表。因此,dirs
不包含ignoreddirs
。然而,它可能包含一些元素。检查这一点的一种方法是检查他们的交叉点:
if len(set(ignoreddirs).intersection(set(dirs))) > 0:
continue