Syncing two folders¶

This example is about syncing two folders or creating a backup.

from pyquickhelper.filehelper import synchronize_folder
dest = "temp_sync"
import os
if not os.path.exists(dest):
    print("creating", dest)
    os.makedirs(dest)
else:
    print("folder already created", dest)

Out:

creating temp_sync
try:
    copy = os.path.dirname(__file__)
except NameError:
    # __file__ does not exist when run with sphinx-gallery
    copy = "."

paths_to_try = [os.path.join("..", "notebooks"),
                os.path.join("_doc", "notebooks")]

for path in paths_to_try:
    src = os.path.abspath(path)
    if os.path.exists(src):
        break

src = os.path.abspath(src)
synchronize_folder(src, dest, fLOG=print)

Out:

[synchronize_folder] from 'somewhere/workspace/pyquickhelper/pyquickhelper_UT_37_std/_doc/notebooks'
[synchronize_folder] to   'temp_sync'
[synchronize_folder]   exploring f1='somewhere/workspace/pyquickhelper/pyquickhelper_UT_37_std/_doc/notebooks'
[synchronize_folder]   number of found files (p1) 16 2019-05-18 23:06:13.543861
[synchronize_folder]   exploring f2='temp_sync'
[synchronize_folder]     number of found files (p2) 1 2019-05-18 23:16:09.901254
[synchronize_folder] Starting synchronisation.
[synchronize_folder] ... 1/15 (current: 'README.txt' :: >+)
[synchronize_folder] ... 2/15 (current: 'check_matplotlib_backend.ipynb' :: >+)
[synchronize_folder] ... 3/15 (current: 'compare_python_distribution.ipynb' :: >+)
[synchronize_folder] ... 4/15 (current: 'example_about_files.ipynb' :: >+)
[synchronize_folder] ... 5/15 (current: 'example_completion.ipynb' :: >+)
[synchronize_folder] ... 6/15 (current: 'example_documentation.ipynb' :: >+)
[synchronize_folder] ... 7/15 (current: 'example_pyquickhelper.ipynb' :: >+)
[synchronize_folder] ... 8/15 (current: 'example_with_comments.ipynb' :: >+)
[synchronize_folder] ... 9/15 (current: 'exemple_of_fix_menu.ipynb' :: >+)
[synchronize_folder] ... 10/15 (current: 'git_dataframes.ipynb' :: >+)
[synchronize_folder] ... 11/15 (current: 'having_a_form_in_a_notebook.ipynb' :: >+)
[synchronize_folder] ... 12/15 (current: 'javascript_extension.ipynb' :: >+)
[synchronize_folder] ... 13/15 (current: 'nbimage.png' :: >+)
[synchronize_folder] ... 14/15 (current: 'notebook_with_svg.ipynb' :: >+)
[synchronize_folder] ... 15/15 (current: 'simple_example.ipynb' :: >+)
[synchronize_folder] END: no copy

Total running time of the script: ( 0 minutes 0.050 seconds)

Gallery generated by Sphinx-Gallery