joinpath

joinpath(parts...) -> AbstractString

Join path components into a full path. If some argument is an absolute path, then prior components are dropped.

Examples

  1. Join path components:

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

    This example joins the provided path components "path", "to", and "file.txt" into a full path.

  2. Handle absolute paths:

    julia> joinpath("/home/user", "documents", "file.txt")
    "/home/user/documents/file.txt"

    If any of the path components is an absolute path (starting with /), prior components are dropped, and the absolute path is returned.

  3. Join path components using variables:
    julia> base = "/usr/local"
    julia> folder = "share"
    julia> file = "README.txt"
    julia> joinpath(base, folder, file)
    "/usr/local/share/README.txt"

    It is possible to use variables as path components in joinpath.

Common mistake example:

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

In this example, one of the path components is an absolute path ("/file.txt"), causing the prior components to be dropped. Ensure that you provide relative paths or handle absolute paths appropriately to avoid unexpected behavior.

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: