cp

cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false, follow_symlinks::Bool=false)

Copy the file, link, or directory from src to dest. remove_destination=true will first remove an existing dst.

If follow_symlinks=false, and src is a symbolic link, dst will be created as a symbolic link. If follow_symlinks=true and src is a symbolic link, dst will be a copy of the file or directory src refers to.

Examples

julia> cp("path/to/source/file.txt", "path/to/destination/file.txt")

This example copies the file file.txt from the source directory to the destination directory.

julia> cp("path/to/source/file.txt", "path/to/destination/directory/")

This example copies the file file.txt from the source directory to the destination directory, preserving the filename.

julia> cp("path/to/source/directory/", "path/to/destination/directory/")

This example copies the entire contents of the source directory to the destination directory, including all files and subdirectories.

julia> cp("path/to/source/file.txt", "path/to/destination/file.txt"; remove_destination=true)

This example removes any existing file with the same name at the destination before performing the copy operation.

julia> cp("path/to/source/symlink", "path/to/destination/symlink"; follow_symlinks=true)

This example copies the file or directory that the symbolic link symlink in the source directory refers to, and creates a new symbolic link with the same name in the destination directory.

julia> cp("path/to/source/symlink", "path/to/destination/symlink"; follow_symlinks=false)

This example creates a new symbolic link in the destination directory with the same name as the symbolic link in the source directory, without following the link to its target.

Common mistake example:

julia> cp("nonexistent/file.txt", "path/to/destination/")
ERROR: SystemError: source path does not exist or is inaccessible: nonexistent/file.txt

In this example, the source file or directory does not exist. Make sure that the source path is correct and the file or directory exists before using the cp function.

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: