Add method glob to get child items with a glob pattern.

This commit is contained in:
Ethan Dalool 2020-07-07 22:25:44 -07:00
parent df02690361
commit ff9895a390

View file

@ -2,6 +2,8 @@ import glob
import os
import re
from voussoirkit import winglob
class PathclassException(Exception):
pass
@ -151,6 +153,15 @@ class Path:
def extension(self):
return Extension(os.path.splitext(self.absolute_path)[1])
def glob(self, pattern):
if '/' in pattern or '\\' in pattern:
# If the user wants to glob names in a different path, they should
# create a Pathclass for that directory first and do it normally.
raise TypeError('glob pattern should not have path separators')
children = winglob.glob(pattern)
children = [self.with_child(child) for child in children]
return children
@property
def is_dir(self):
return os.path.isdir(self.absolute_path)