RE: os.scandir problem

Anders Munch <[email protected]> Tue, 31 Mar 2026 07:48:29 +0000
Newsgroups gmane.comp.python.general
Message-ID <PAXPR05MB966366476885B05E4C68B533B453A@PAXPR05MB9663.eurprd05.prod.outlook.com>
Rob Cliffe via Python-list <[email protected]>  wrote:
> When the RAM disc is empty,
>      os.scandir("R:")
> raises a FileNotFoundError instead of (as I would have expected) returning an empty iterator.

os.scandir is a simple wrapper around FindFirstFile/FindNextFile.  If FindFirstFileW("R:", "*.*") sets the file-not-found Windows error code, then that will be turned into the exception that you see.

You might want to try os.scandir("R:\\").  Your issue could have something to do with the current directory for the R: drive not being well-defined.

regards, Anders