os.walk ignore directorys and its content -


i'm trying ignore directory , files in in specific path , code

    x = open(wbcmd, 'a') x.write('set path="c:\program files\winrar\";%path% c:/program files/winrar/\n') x.write('rar.exe -r "backup.rar" -m5 -ep1') chkdict = {} setdef = chkdict.setdefault root, dirs, files in os.walk(foldername):     if ignoreddirs in dirs:         continue     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 array looks this

ignoreddirs = ["bin"] 

dirs , ignoreddirs both lists of strings. therefore, dirs not contain ignoreddirs. may, contain of elements. 1 way check check intersection:

if len(set(ignoreddirs).intersection(set(dirs))) > 0:     continue 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -