title: Python Os.walk Filter Filenames (What extensions not to include and skip dirs)
body: <pre><code>filetypes = ("*.jpg","*.txt","*.csv")
  filelist = []
  
  for root, dirnames, filenames in os.walk("c:\\"):
   for ft in filetypes:
    for f in fnmatch.filter(filenames, ft):
     filelist.append(os.path.join(root, f))
  </code></pre>
  
  <p>I have this code which will add to my list only files with the extensions I provide, </p>
  
  <p>1) I want to do the opposite add all file extensions <code>"*.*"</code> and filter some of them I don't need for example <code>"*.dat","*.dll","*.log","*.exe"</code> </p>
  
  <p>2) Also I do not need files from <code>c:\\windows c:\\program files c:\\else</code> can I filter it too?</p>
  
  <p>3) I need it to be fast found this example code from other answer it seems to be faster but what is main speed issue in this type of function os.walk? If so there is scandir github project 7-20 times faster os.walk improved function, or if it's the filtering of file matches by extensions i want to filter 20+ extensions any suggestions?</p>
  
  <pre><code>    import os
      extns = ('.jpg', '.jpeg', '.png', '.tif', '.tiff')
      matches = []
      for root, dirnames, fns in os.walk("C:\\"):
          matches.extend(os.path.join(root, fn) for fn in fns if fn.lower().endswith(extns))
  </code></pre>
  
  <p>Your help is very much appreciated </p>