code: def _dirmatch(path, matchwith):
      
      matchlen = len(matchwith)
      if (path.startswith(matchwith)
          and path[matchlen:matchlen + 1] in [os.sep, '']):
          return True
      return False
docs: Check if path is within matchwith's tree.
  
      >>> _dirmatch('/home/foo/bar', '/home/foo/bar')
      True
      >>> _dirmatch('/home/foo/bar/', '/home/foo/bar')
      True
      >>> _dirmatch('/home/foo/bar/etc', '/home/foo/bar')
      True
      >>> _dirmatch('/home/foo/bar2', '/home/foo/bar')
      False
      >>> _dirmatch('/home/foo/bar2/etc', '/home/foo/bar')
      False