I would like to suggest to change the method name basename
to filename
.
The only reason is that it麓s easier to remember.
So we would have:
julia> f = "/my/path/name.txt";
julia> dirname(f)
"/my/path"
julia> filename(f)
"name.txt"
Presumably basename
was chosen since it matches the shell function of the same name, which I _think_ is POSIX standard.
Isn't basename without the extension?
No, basename
includes the extension, both in Julia and in the shell.
I was remembering this :
basename /home/jsmith/base.wiki .wiki
Removes .wiki from the end.
The name is standard in shell, Python, Perl, Ruby, etc.
If that's a standard, that's fine. Thanks!
There is (at least in 0.6.2) no filename(path)
, but this helps:
julia> filename(path) = splitext(basename(path))[1]
filename (generic function with 1 method)
julia> filename("test.png")
"test"
it seems shell eg. coreutils and posix do not match.
basename
@ julia ~ basename
@ posix
nothing
@ julia ~ basename
@ coreutils
Here is the coreutils version :
function Base.basename(path::String, suffix::String)
(n,e) = splitext(basename(path))
suffix==e ? n : path
end
@test Base.basename("foo", ".htm") == "foo"
@test Base.basename("foo.htm", ".htm") == "foo"
@test Base.basename("foo.jpg", ".htm") == "foo.jpg"
Most helpful comment
Presumably
basename
was chosen since it matches the shell function of the same name, which I _think_ is POSIX standard.