title: How to exclude files in path directory using pathlib in python the proper way?
body: <p>I have a datapath to a file couple of data files, let us say data01.txt, data02.txt and so on. During processing the user will provide mask files for the data (potentially also via an external tool). Mask files will contain the string 'mask', e.g., data01-mask.txt.</p>
  
  <pre><code>from pathlib import Path
  p = Path(C:\Windowns\test\data01.txt)
  dircontent = list(p.parent.glob('*'))
  </code></pre>
  
  <p>Gives me a list of all the filespath as <code>Path</code> objects including potential masks. Now I want a list that gives me the directory content but not including any file containing mask. I have <a href="https://stackoverflow.com/questions/216995/how-can-i-use-inverse-or-negative-wildcards-when-pattern-matching-in-a-unix-linu">tried this approach</a> to use fancy regex <code>*![mask]*</code> but I do not get it to work. </p>
  
  <p>Using,</p>
  
  <pre><code>dircontentstr = [str(elem) for elem in x]
  filtereddir = [elem.find('mask') for elem in dircontentstr if elem.find('mask')==-1]
  </code></pre>
  
  <p>I can get the desired result, but it seems silly to then convert back to <code>Path</code> elements. Is there a straight forward way to exclude from the directory list?</p>