[Python 3.x] ファイルやディレクトリの一覧を取得する

1.os.listdir

2.glob.glob
  ※[3.6 or later] 中でos.scandir()を使用

3.pathlib.Path.iterdir  [new in 3.4]
  ※[3.12        ] 中でos.listdir()を使用

4.pathlib.Path.glog
  ※[3.6 or later] 中でos.scandir()を使用

5.os.scandir            [new in 3.5]
import glob
import os
from pathlib import Path


filenames: list[str] = [
    name for name in os.listdir(".")
        if os.path.isfile(name) and name.endswith(".py")
]


filenames2: list[str] = [
    name for name in glob.glob("*.py")
        if os.path.isfile(name)
]


paths: list[Path] = [
    path for path in Path(".").iterdir()
        if path.is_file() and path.suffix == ".py"
]


paths2: list[Path] = [
    path for path in Path(".").glob("*.py")
        if path.is_file()
]


entries: list[os.DirEntry[str]] = [
    entry for entry in os.scandir(".")
        if entry.is_file() and entry.name.endswith(".py")
]