title: How to force script to close all opened files based on theirs directory?
body: <p>Is it possible to close opened files based only on theirs directories? I would like to close files with specific extension. If it's not possible, I can close all opened files. My code has become so long that I cannot control the closing of files in the other way. I'm preparing application for external users and I developed "reset" button, but I met a problem with accessing to some folder cause by these files are still opened. </p>
  
  <p>I'm using psutil to get list of all opened files by my .py script.</p>
  
  <pre><code>[popenfile(path='C:\\Users\\Jan\\AppData\\Local\\Microsoft\\Windows\\Explorer\\iconcache_48.db', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\intersection1B.shp', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\intersection1A.dbf', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\intersection1A.shp', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\explorerframe.dll.mui', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\polygonSet1B.shp', fd=-1),
  popenfile(path='C:\\Users\\Jan\\AppData\\Local\\Microsoft\\Windows\\Explorer\\iconcache_idx.db', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\user32.dll.mui', fd=-1),
  popenfile(path='C:\\Users\\Jan\\AppData\\Local\\Microsoft\\Windows\\Explorer\\thumbcache_idx.db', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\intersection1B.shx', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\PolygonSet1A.dbf', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\obszar_zainteresowania.dbf', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\dui70.dll.mui', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\intersection1B.dbf', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\polygonSet1B.dbf', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\shell32.dll.mui', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\propsys.dll.mui', fd=-1),
  popenfile(path='C:\\Users\\Jan\\AppData\\Local\\Microsoft\\Windows\\Explorer\\thumbcache_96.db', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\obszar_zainteresowania.shp', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\NetworkItemFactory.dll.mui', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\comdlg32.dll.mui', fd=-1),
  popenfile(path='C:\\Windows\\Fonts\\StaticCache.dat', fd=-1),
  popenfile(path='C:\\Users\\Jan\\AppData\\Local\\Microsoft\\Windows\\Explorer\\iconcache_256.db', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\PolygonSet1A.shp', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\windows.storage.dll.mui', fd=-1),
  popenfile(path='D:\\jan\\apka_update\\temp\\17-Z1-20180704_Lk7_156.000-180.000_niepelne\\intersection1A.shx', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\mpr.dll.mui', fd=-1),
  popenfile(path='C:\\Windows\\System32\\pl-PL\\KernelBase.dll.mui', fd=-1),
  popenfile(path='C:\\Users\\Jan\\AppData\\Local\\Microsoft\\Windows\\Explorer\\iconcache_16.db', fd=-1)]    
  </code></pre>