Search code examples
python-3.xscandir

Create os.DirEntry


Does anyone have a hack to create an os.DirEntry object other than listing the containing directory?

I want to use that for 2 purposes:

  1. tests
  2. API where container and contained are queried at the same time

Solution

  • In Python 3.5 os.DirEntry is not yet exposed.

    Details: https://bugs.python.org/issue27038

    Python 3.6 exposes os.DirEntry type, but it cannot be instantiated.

    On Python 3.5 a type() on a DirEntry object returns posix.DirEntry