Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rename public #55652

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,16 @@ julia> mv("hello.txt", "goodbye.txt", force=true)
julia> rm("goodbye.txt");

```

!!! note
The `mv` function is different from the `mv` command. The `mv` function by
nhz2 marked this conversation as resolved.
Show resolved Hide resolved
default will error if `dst` exists, while the command will delete
an existing `dst` file by default.
Also the `mv` function always operates on
the assumption that `dst` is a file, while the command does different things depending
on whether `dst` is a directory or a file.
Using `force=true` when `dst` is a directory will result in loss of all the contents present
in the `dst` directory, and `dst` will become a file that has the contents of `src` instead.
"""
function mv(src::AbstractString, dst::AbstractString; force::Bool=false)
if force
Expand Down Expand Up @@ -1192,6 +1202,8 @@ If a path contains a "\\0" throw an `ArgumentError`.
On other failures throw an `IOError`.
Return `newpath`.

This is a lower level filesystem operation used to implement [`mv`](@ref).

OS-specific restrictions may apply when `oldpath` and `newpath` are in different directories.

Currently there are a few differences in behavior on Windows which may be resolved in a future release.
Expand All @@ -1202,6 +1214,9 @@ Specifically, currently on Windows:
4. `rename` may remove `oldpath` if it is a hardlink to `newpath`.

See also: [`mv`](@ref).

!!! compat "Julia 1.12"
This method was publicized in Julia 1.12.
nhz2 marked this conversation as resolved.
Show resolved Hide resolved
"""
function rename(oldpath::AbstractString, newpath::AbstractString)
err = ccall(:jl_fs_rename, Int32, (Cstring, Cstring), oldpath, newpath)
Expand Down
3 changes: 3 additions & 0 deletions base/public.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public
reseteof,
link_pipe!,

# filesystem operations
rename,

# misc
notnothing,
runtests,
Expand Down
1 change: 1 addition & 0 deletions doc/src/base/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Base.Filesystem.operm
Base.Filesystem.cp
Base.download
Base.Filesystem.mv
Base.Filesystem.rename
Base.Filesystem.rm
Base.Filesystem.touch
Base.Filesystem.tempname
Expand Down