Search code examples
julia

How to move file from one directory to another (Julia)?


I have two different paths (directory path and file path). I need to move the file from one directory to another. How i should do it?


Solution

  • Use the mv function.

    help?> mv
    …
    
      mv(src::AbstractString, dst::AbstractString; force::Bool=false)
    
      Move the file, link, or directory from src to dst. force=true will first remove an existing dst. Return dst.
    
    

    One thing to note is that both src and dest must be complete paths i.e. if your source file path is src = /home/me/file.txt and you want to move that to be under the directory path dstdir = /home/me/.julia, the call should be mv(src, joinpath(dstdir, basename(src)).

    (Just to be clear, the arguments can be absolute paths or relative paths, either works. By "complete paths" I only mean that both src and dst have to include the file name, dst can't be just a directory unless you wish you overwrite the directory itself.)