Replace pathlib.glob() with os.scandir() in fs.py

This commit is contained in:
Andrew Senetar 2022-03-29 22:35:38 -05:00
parent 50f5db1543
commit 43fcc52291
Signed by: arsenetar
GPG Key ID: C63300DCE48AB2F1
1 changed files with 7 additions and 5 deletions

View File

@ -377,7 +377,8 @@ class Folder(File):
@property
def subfolders(self):
if self._subfolders is None:
subfolders = [p for p in self.path.glob("*") if not p.is_symlink() and p.is_dir()]
with os.scandir(self.path) as iter:
subfolders = [p.path for p in iter if not p.is_symlink() and p.is_dir()]
self._subfolders = [self.__class__(p) for p in subfolders]
return self._subfolders
@ -410,10 +411,11 @@ def get_files(path, fileclasses=[File]):
assert all(issubclass(fileclass, File) for fileclass in fileclasses)
try:
result = []
for path in path.glob("*"):
file = get_file(path, fileclasses=fileclasses)
if file is not None:
result.append(file)
with os.scandir(path) as iter:
for item in iter:
file = get_file(item, fileclasses=fileclasses)
if file is not None:
result.append(file)
return result
except EnvironmentError:
raise InvalidPath(path)