Python Glossary Русский

all Python 3osfunction

os.path.getctime

os.path — metadata (stat)

Return the metadata-change time (POSIX) or creation time (Windows) of a file.

Syntax

os.path.getctime(path)

Its meaning depends on the system: on Unix it is the time of the last metadata change — permissions, owner, link count — not creation; on Windows it is the creation time. So getctime cannot portably give a "file creation date". Where the system records creation time, os.stat(path).st_birthtime provides it.

Examples

import os
import time
print(os.path.getctime(os.__file__) > 0)   # → True
print(os.path.getctime(os.__file__) == os.stat(os.__file__).st_ctime)   # → True: getctime — это os.stat(path).st_ctime
print(time.ctime(os.path.getctime(os.__file__)))   # → на Windows это время создания файла, на POSIX — время последнего изменения метаданных, например Tue Jul 21 10:15:03 2026
print(os.path.getctime('нет-такого-файла'))   # → FileNotFoundError

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy