Add method glob to get child items with a glob pattern.
This commit is contained in:
parent
df02690361
commit
ff9895a390
1 changed files with 11 additions and 0 deletions
|
@ -2,6 +2,8 @@ import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from voussoirkit import winglob
|
||||||
|
|
||||||
|
|
||||||
class PathclassException(Exception):
|
class PathclassException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -151,6 +153,15 @@ class Path:
|
||||||
def extension(self):
|
def extension(self):
|
||||||
return Extension(os.path.splitext(self.absolute_path)[1])
|
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
|
@property
|
||||||
def is_dir(self):
|
def is_dir(self):
|
||||||
return os.path.isdir(self.absolute_path)
|
return os.path.isdir(self.absolute_path)
|
||||||
|
|
Loading…
Reference in a new issue