On this page
  1. os.listdir
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

os.listdir

Prev: os.link | Up: os | Next: os.lstat
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.listdir
Tags: #public #python3 #stdlib #os


Import

import os
from os import listdir

Signature & Overview

os.listdir(path=None)

Return a list containing the names of the files in the directory.

Usage

import os
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    (Path(tmp) / "a.txt").write_text("1", encoding="utf-8")
    assert os.listdir(tmp) == ["a.txt"]

Gotchas

REPL Inspect

from os import listdir
help(listdir)

Linked from

Related notes