1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-01-22 14:41:39 +00:00

Update directory scanning to use os.scandir()

- Change to use os.scandir() instead of os.walk() to leverage DirEntry objects.
- Avoids extra calls to stat() on files during fs.can_handle()
- See 3x speed improvement on Windows in some cases
This commit is contained in:
2022-03-29 23:37:56 -05:00
parent 43fcc52291
commit efd500ecc1
2 changed files with 41 additions and 43 deletions

View File

@@ -379,7 +379,7 @@ class Folder(File):
if self._subfolders is None:
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]
self._subfolders = [self.__class__(Path(p)) for p in subfolders]
return self._subfolders
@classmethod
@@ -398,7 +398,7 @@ def get_file(path, fileclasses=[File]):
for fileclass in fileclasses:
if fileclass.can_handle(path):
if type(path) is os.DirEntry:
return fileclass(path.path)
return fileclass(Path(path.path))
return fileclass(path)