mkpath(path, [mode])

Create all directories in the given path, with permissions mode. mode defaults to 0o777, modified by the current file creation mask.


  1. Create directories with default permissions:

    julia> mkpath("mydir")

    This example creates a directory named "mydir" with default permissions (0o777).

  2. Create directories with custom permissions:

    julia> mkpath("mydir", 0o755)

    It creates a directory named "mydir" with permissions 0o755.

  3. Create nested directories:

    julia> mkpath("parent/child/grandchild")

    This example creates nested directories "parent", "child", and "grandchild" within each other.

  4. Handle existing directories:
    julia> mkpath("existing_dir")

    If the directory already exists, mkpath doesn't raise an error and returns the path as is.

Common mistake example:

julia> mkpath("/root/mydir")
ERROR: PermError: operation not permitted (EPERM)

In this example, the user is trying to create a directory in a location where they don't have the necessary permissions (e.g., /root directory). Make sure the user has the required permissions to create directories at the specified 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: