Julia: Rename `basename` to `filename`

Created on 23 May 2017  路  8Comments  路  Source: JuliaLang/julia

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"

Most helpful comment

Presumably basename was chosen since it matches the shell function of the same name, which I _think_ is POSIX standard.

All 8 comments

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"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

tkoolen picture tkoolen  路  3Comments

wilburtownsend picture wilburtownsend  路  3Comments

manor picture manor  路  3Comments

omus picture omus  路  3Comments

felixrehren picture felixrehren  路  3Comments