PyDocs

Nav

Generic Operating System Services

listdir

os

function
  • listdir(path='.')
Return a list containing the names of the files in the directory.

path can be specified as either str, bytes, or a path-like object.  If
path is bytes, the filenames returned will also be bytes; in all other
circumstances the filenames returned will be str.
If path is None, uses the path='.'.
On some platforms, path may also be specified as an open file
descriptor; the file descriptor must refer to a directory.  If this
functionality is unavailable, using it raises NotImplementedError.

The list is in arbitrary order.  It does not include the special
entries '.' and '..' even if they are present in the directory.
Changed in 3.2, 3.3, 3.6, 3.15
  • 3.2: The path parameter became optional.
  • 3.3: Added support for specifying path as an open file descriptor.
  • 3.6: Accepts a path-like object.
  • 3.15: os.listdir(-1) now fails with OSError(errno.EBADF) rather than listing the current directory.
0 Examples
No examples for os/listdir.
See Also
No see-alsos for os/listdir
0 Notes
No notes for listdir