Skip to content

Commit

Permalink
feat(DirIterator): add get_file_path / get_file_info methods
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Apr 13, 2023
1 parent 2b32d7a commit 037a58c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions prettyqt/core/diriterator.py
@@ -1,6 +1,24 @@
from __future__ import annotations

import pathlib
from typing import Literal

from prettyqt import core
from prettyqt.qt import QtCore
from prettyqt.utils import bidict


ITERATOR_FLAG = bidict(
none=QtCore.QDirIterator.IteratorFlag.NoIteratorFlags,
subdirectories=QtCore.QDirIterator.IteratorFlag.Subdirectories,
follow_symlinks=QtCore.QDirIterator.IteratorFlag.FollowSymlinks,
)

IteratorFlagStr = Literal[
"none",
"subdirectories",
"follow_symlinks",
]


class DirIterator(QtCore.QDirIterator):
Expand All @@ -11,3 +29,14 @@ def __next__(self):
if self.hasNext():
return self.next()
raise StopIteration

def get_file_path(self) -> pathlib.Path:
return pathlib.Path(self.filePath())

def get_file_info(self) -> core.FileInfo:
return core.FileInfo(self.fileInfo())


if __name__ == "__main__":
it = core.DirIterator("C:/Intel")
print(list(it))

0 comments on commit 037a58c

Please sign in to comment.