mktempdir()

mktempdir([parent=tempdir()])

Create a temporary directory in the parent directory and return its path.

Examples

julia> function example_function()
           temp_dir = mktempdir() do dir
               # Perform operations using the temporary directory
               println("Working in temporary directory: ", dir)
               # ...
           end
           # Temporary directory is automatically removed upon completion
           println("Temporary directory removed.")
       end

In this example, the mktempdir function is used to create a temporary directory, and the provided function f is applied to this directory. After the function f completes, the temporary directory is automatically removed.

Note that the mktempdir function can also take an optional parent argument, which specifies the parent directory where the temporary directory will be created. If not provided, tempdir() is used as the default parent directory.

Here's an example that explicitly specifies the parent directory:

julia> parent_dir = "/path/to/parent"
julia> function example_function()
           temp_dir = mktempdir(parent_dir) do dir
               # Perform operations using the temporary directory
               println("Working in temporary directory: ", dir)
               # ...
           end
           # Temporary directory is automatically removed upon completion
           println("Temporary directory removed.")
       end

In this case, the temporary directory will be created inside the /path/to/parent directory.

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: