diff --git a/docs/modules/os.md b/docs/modules/os.md index b6ac9455..c929a660 100644 --- a/docs/modules/os.md +++ b/docs/modules/os.md @@ -38,3 +38,7 @@ Joins the given paths together. ### `os.path.exists(path: str)` Check if the given path exists. + +### `os.path.basename(path: str)` + +Returns the basename of the given path. \ No newline at end of file diff --git a/src/io.h b/src/io.h index 4ce76259..2ae87595 100644 --- a/src/io.h +++ b/src/io.h @@ -169,6 +169,11 @@ inline void add_module_os(VM* vm){ bool exists = std::filesystem::exists(path); return VAR(exists); }); + + vm->bind_func<1>(path_obj, "basename", [](VM* vm, ArgsView args){ + std::filesystem::path path(CAST(Str&, args[0]).sv()); + return VAR(path.filename().string()); + }); } } // namespace pkpy