splitext

splitext(path::AbstractString) -> (AbstractString,AbstractString)

If the last component of a path contains a dot, split the path into everything before the dot and everything including and after the dot. Otherwise, return a tuple of the argument unmodified and the empty string.

Examples

  1. Split a path with an extension:

    julia> splitext("/path/to/file.txt")
    ("/path/to/file", ".txt")

    This example splits the given path into two parts: everything before the dot and everything including and after the dot.

  2. Split a path without an extension:

    julia> splitext("/path/to/file")
    ("/path/to/file", "")

    If the last component of the path does not contain a dot, the function returns a tuple with the original path and an empty string.

  3. Split a path with multiple dots:
    julia> splitext("/path/to/archive.tar.gz")
    ("/path/to/archive.tar", ".gz")

    The function splits the path at the last dot, considering it as the extension separator. If there are multiple dots in the last component, only the last one is used for splitting.

Common mistake example:

julia> splitext("/path/to/directory/")
("/path/to/directory/", "")

In this example, the provided path ends with a trailing slash. Since the last component of the path doesn't contain a dot, the function returns the original path and an empty string as the extension. It's important to note that splitext splits the path based on the last dot in the last component, not the presence of a trailing slash.

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
Details

Checking you are not a robot: