Python 3.13+Windowsosfunction
os.path.isreserved()
os.path — existence and type checks
Checks whether a pathname is reserved on the current system: on Windows these are NUL, CON, COM1, names with colons, wildcards, or a trailing dot/space. Windows only, Python 3.13+.
Syntax
os.path.isreserved(path)
It matters when creating files from user-supplied names on Windows: a file named CON or NUL cannot be created, and writing to such a path goes to a device. Every component of the path is checked. Such a name can be saved with a prefix or an alteration — check before creating the file, not after an error.
Examples
import os, ntpath
print(not hasattr(os.path, 'isreserved') or callable(os.path.isreserved)) # → True
print(ntpath.isreserved('NUL')) # → True
print(ntpath.isreserved('COM1')) # → True
print(ntpath.isreserved('report.')) # → True
print(ntpath.isreserved('report.txt')) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy