How to use the scandir.DirEntry function in scandir

To help you get started, we’ve selected a few scandir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benhoyt / scandir / test / test_scandir.py View on Github external
def test_iter_returns_dir_entry(self):
            it = scandir.scandir(TEST_PATH)
            entry = next(it)
            assert isinstance(entry, scandir.DirEntry)
github bleachbit / bleachbit / bleachbit / FileUtilities.py View on Github external
if 'posix' == os.name:
    from bleachbit.General import WindowsError
    pywinerror = WindowsError

try:
    from scandir import walk
    if 'nt' == os.name:
        import scandir
        import bleachbit.Windows

        class _Win32DirEntryPython(scandir.Win32DirEntryPython):
            def is_symlink(self):
                return super(_Win32DirEntryPython, self).is_symlink() or bleachbit.Windows.is_junction(self.path)

        scandir.scandir = scandir.scandir_python
        scandir.DirEntry = scandir.Win32DirEntryPython = _Win32DirEntryPython
except ImportError:
    logger.warning(
        'scandir is not available, so falling back to slower os.walk()')
    from os import walk


def open_files_linux():
    return glob.iglob("/proc/*/fd/*")


def open_files_lsof(run_lsof=None):
    if run_lsof is None:
        def run_lsof():
            return subprocess.check_output(["lsof", "-Fn", "-n"])
    for f in run_lsof().split("\n"):
        if f.startswith("n/"):