zig
zig copied to clipboard
std.fs.path: add stem()
This adds a function to std.fs.path
returning the stem of the given path. I think this is a worthwhile addition in the long term. It's a pretty common function for a standard library. And I hope there isn't already some other really easy way to do this. I don't think there is.
I needed this today when I wanted to append a file name and change its file extension, like this:
thisDir() ++ "/" ++ stem(path) ++ ".ext",
See here for how other standard libraries do this:
- https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.stem
- https://crystal-lang.org/api/1.6.0/Path.html#stem%3AString-instance-method
- https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem