org.pycforge.os · Author: PyCForge
License: GPL-3.0-only · Created: 2026-11-20
Runtime conversion · Direct declared calls
Using this import · Functions · Conversion contract · Worked examples
path.abspath · path.basename · path.dirname · path.exists · getcwd · getenv · path.getmtime · path.getsize · path.isabs · path.isdir · path.isfile · path.join · listdir · makedirs · path.normpath · replace · path.splitext
Inspect and update files through a bounded native OS interface.
Use *import os as fs. Path functions live under fs.path. Other functions live directly under fs.
Unicode str paths and a native Windows or POSIX target. Filesystem calls use the running program's working directory and environment. Returned names must be representable as Unicode scalars in the Runtime's UTF-8 strings. Windows uses the wide-character API. Path joins accept 1 to 64 positional components. Expanded arguments, file descriptors, bytes paths, PathLike objects, dir_fd and Typed conversion are outside this profile. File and allocation budgets apply. Directory entries follow native enumeration order. Parent directories created before a failure remain on disk. Place a replacement source beside its destination for same-filesystem replacement.
Native filesystem and environment operations.
Declare *import os as fs. Use fs.path.join for paths and fs.listdir for directory contents. Paths and environment variables use the operating system running the generated program.
Unicode str paths and a native Windows or POSIX target. Filesystem calls use the running program's working directory and environment. Returned names must be representable as Unicode scalars in the Runtime's UTF-8 strings. Windows uses the wide-character API. Path joins accept 1 to 64 positional components. Expanded arguments, file descriptors, bytes paths, PathLike objects, dir_fd and Typed conversion are outside this profile. File and allocation budgets apply. Directory entries follow native enumeration order. Parent directories created before a failure remain on disk. Place a replacement source beside its destination for same-filesystem replacement.
Return an absolute normalized path using the current working directory.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Return an absolute normalized path using the current working directory.
Return the final pathname component.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Return the final pathname component.
Return the directory portion of a pathname.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Return the directory portion of a pathname.
Test whether the target of the pathname exists.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Test whether the target of the pathname exists.
Return the working directory of the running program.
Normalized semantic slots: . These slots are supplied by the engine; the signature above defines source arguments and defaults.
Returns: Return the working directory of the running program.
Return the environment value or the supplied default if the variable is absent.
Normalized semantic slots: key, default. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: Name of the environment variable.
Argument 2: Value returned unchanged if the variable is absent.
Returns: Return the environment value or the supplied default if the variable is absent.
Read the last modification time in seconds since the Unix epoch.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Read the last modification time in seconds since the Unix epoch.
Read the size in bytes from the filesystem.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Read the size in bytes from the filesystem.
Test whether a path is absolute under Python 3.12 target rules.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Test whether a path is absolute under Python 3.12 target rules.
Test whether the pathname refers to a directory.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Test whether the pathname refers to a directory.
Test whether the pathname refers to a regular file.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Test whether the pathname refers to a regular file.
Join one or more path components using target operating-system rules.
Normalized semantic slots: path, paths. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Argument 2: Additional positional Unicode components.
Returns: Join one or more path components using target operating-system rules.
List directory entry names, excluding the dot entries. An omitted path or None selects the working directory.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: List directory entry names, excluding the dot entries. An omitted path or None selects the working directory.
Create missing directories. The supplied mode applies to the leaf directory.
Normalized semantic slots: name, mode, exist_ok. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: The directory path to create.
Argument 2: Permission bits for the leaf directory on POSIX.
Argument 3: Whether an existing directory is acceptable.
Returns: Create missing directories. The supplied mode applies to the leaf directory.
Normalize separators, dot components and parent references.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Normalize separators, dot components and parent references.
Rename a file or directory, replacing an eligible destination.
Normalized semantic slots: src, dst. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: Existing source path.
Argument 2: Destination path.
Returns: Rename a file or directory, replacing an eligible destination.
Split the last filename extension from the root.
Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.
Argument 1: A Unicode pathname.
Returns: Split the last filename extension from the root.
Compare your run with the expected output below. The SDK checks conversion when authoring a package. Opening Help and registering a package do not execute the examples.
*import os as fs
def main():
fs.makedirs("reports", exist_ok=True)
with open("reports/draft", "w", encoding="utf-8") as stream:
stream.write("finished")
fs.replace("reports/draft", "reports/final.txt")
final = "reports/final.txt"
print(fs.path.isfile(final), fs.path.getsize(final))
print(fs.path.isdir("reports"), fs.path.exists(final), "final.txt" in fs.listdir("reports"))
print(fs.path.getmtime(final) == fs.path.getmtime(final), fs.getenv("", "default"))
return 0
Expected standard output:
True 8 True True True True default
Expected exit code: 0
*import os as fs
def main():
path = fs.path.join("reports", "sales.csv")
filename = fs.path.basename(path)
print(filename, fs.path.splitext(filename))
print(fs.path.dirname(path), fs.path.normpath(fs.path.join("x", "..", "reports")))
print(fs.path.isabs(fs.path.abspath(path)), fs.path.abspath(".") == fs.getcwd())
return 0
Expected standard output:
sales.csv ('sales', '.csv')
reports reports
True True
Expected exit code: 0