Issue 28299: DirEntry.is_dir() evaluates True for a file on Windows (original) (raw)

Issue28299

Created on 2016-09-28 12:47 by David Staab, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testmodule.zip David Staab,2016-09-28 12:47 Python module and directory structure for reproducing test
Messages (2)
msg277611 - (view) Author: David Staab (David Staab) Date: 2016-09-28 12:47
I'm using Python 3.5.2 on Windows 10 Pro to run the following code with the attached file structure. The test code is: from os import DirEntry, scandir def test_is_dir(): for item in os.scandir(TEST_DIR): if item.is_dir: print(item.path) return TEST_DIR = '.' test_is_dir() The console output is: =============== Connected to pydev debugger (build 162.1967.10) .\20160707 .\scratchpad.py Process finished with exit code 0 =============== I would expect to only see '.\20160707', but "if item.is_dir:" always evaluates to True. I notice that changing the import line to "from os import DirEntry, scandir" yields the exception "ImportError: cannot import name 'DirEntry'".
msg277613 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2016-09-28 12:50
is_dir is a *method*. To find out if an entry is a directory, you need to call it. So you need from os import DirEntry, scandir def test_is_dir(): for item in os.scandir(TEST_DIR): if item.is_dir(): # ^^ note change print(item.path) return TEST_DIR = '.' test_is_dir()
History
Date User Action Args
2022-04-11 14:58:37 admin set github: 72486
2016-09-28 12:54:02 zach.ware set stage: resolved
2016-09-28 12:50:52 paul.moore set status: open -> closedresolution: not a bugmessages: +
2016-09-28 12:47:27 David Staab create