basename(path::AbstractString) -> AbstractString

Get the file name part of a path.


  1. Extract the base name from a file path:

    julia> basename("/path/to/file.txt")

    This example extracts the file name part from the given file path.

  2. Extract the base name from a directory path:

    julia> basename("/path/to/directory/")

    It returns the last component of the directory path, which is the directory name.

  3. Handle edge cases with empty paths:
    julia> basename("")

    When an empty path is provided, the function returns an empty string.

Common mistake example:

julia> basename("/path/to/file.txt/")

In this example, the trailing slash is included in the extracted base name. It's important to note that basename does not remove the trailing slash if it exists. It only returns the last component of the path.

See Also

abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: