Copy only modified files to destination folder

I am wondering, if there is a package or a command to copy only new files to a destination folder (one way synchronization). I have tried to find something here and on GitHub, but failed :frowning:

Are you loooking for a pure Julia solution?

If rsync is available on your system, I think it would be the most convenient option:


run(`rsync --ignore-existing ...`)

you could tell it to skip files that already exist (but there is also lots of other options like updating the file only if the one in the destination is older than in the source folder).

Thanks for the proposal! - Meanwhile I have researched for suitable Python functions, here is my snippet (this works, if it is not necessary to compile an App afterwards …):

using PyCall
# --- establish PyObjects of the necessary functions "copy_file" & "copy_tree" & "remove_tree":
py_setuptools   = PyCall.pyimport("setuptools")
py_distutils    = py_setuptools.distutils
# py_copy_file = PyCall.pyimport("setuptools.distutils.file_util.copy_file") # is not possible
py_copy_file    = py_distutils.file_util.copy_file
py_copy_tree    = py_distutils.dir_util.copy_tree
py_remove_tree  = py_distutils.dir_util.remove_tree

# --- source and destination file names and folders:
temp_dir        = "/media/stefan/DATA/data/temp"
src_dir         = joinpath(temp_dir,    "src");     mkpath(src_dir)
dst_dir_A       = joinpath(temp_dir,    "dst_A");   mkpath(dst_dir_A)
dst_dir_B       = joinpath(temp_dir,    "dst_B")    
file_a_src      = joinpath(src_dir,     "a.txt")
file_b_src      = joinpath(src_dir,     "b.txt")
file_b_dst_A    = joinpath(dst_dir_A,   "b.txt")

# --- delete 2nd destination folder, if it exist:
@show py_remove_tree(dst_dir_B, verbose=true,   dry_run=true)
    @show py_remove_tree(dst_dir_B, verbose=true,  dry_run=false)    
    Base.invokelatest(Base.display_error, Base.catch_stack())

# --- write content to source files:
fid = open(file_a_src, "w");    print(fid, "Hello Julia!");   close(fid)
fid = open(file_b_src, "w");    print(fid, "Hello Python!");  close(fid)

# --- copy folder (entire content):
list_of_files = py_copy_tree(src_dir, dst_dir_A, verbose=true); @show list_of_files 

# --- copy folder to non-existing destination folder, it is created automatically:
list_of_files = py_copy_tree(src_dir, dst_dir_B, verbose=true); @show list_of_files 

# --- one-directional synchronization of destination directory-tree (copy only modified files):
# --- 1.) modify one file in destianation directory-tree:
fid = open(file_b_dst_A, "w");    print(fid, "Hello Python! - Where is Julia?");  close(fid)

# --- 2.) copy only new files (keep content of modified file "file_b_dst_A" in dst-folder):
list_of_files = py_copy_tree(src_dir, dst_dir_A, verbose=true, update=true);  @show list_of_files
@show read(file_b_dst_A, String)

# --- copy file only, if source file is new than destination file (one-directional synchronization)
list_of_files = py_copy_file(file_b_src, file_b_dst_A, verbose=true, update=true);  @show list_of_files
@show read(file_b_src,   String)
@show read(file_b_dst_A, String)