Skip to contents

This function performs a full asymmetric synchronization of the right directory based on the left directory. It includes the following synchronization steps (see Details below):

Usage

full_asym_sync_to_right(
  left_path = NULL,
  right_path = NULL,
  sync_status = NULL,
  by_date = TRUE,
  by_content = FALSE,
  recurse = TRUE,
  force = TRUE,
  backup = FALSE,
  backup_dir = "temp_dir",
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

sync_status

Object of class "syncdr_status", output of compare_directories().

by_date

Logical. If TRUE, synchronize based on file modification dates (default is TRUE).

by_content

Logical. If TRUE, synchronize based on file contents (default is FALSE).

recurse

Logical. If TRUE (default), files are copied to corresponding subdirectories in the destination folder. If FALSE, files are copied to the top level of the destination folder without creating subdirectories if they do not exist.

force

Logical. If TRUE (by default), directly perform synchronization of the directories. If FALSE, Displays a preview of actions and prompts the user for confirmation before proceeding. Synchronization is aborted if the user does not agree.

backup

Logical. If TRUE, creates a backup of the right directory before synchronization. The backup is stored in the location specified by backup_dir.

backup_dir

Path to the directory where the backup of the original right directory will be stored. If not specified, the backup is stored in temporary directory (tempdir).

verbose

logical. If TRUE, display directory tree before and after synchronization. Default is FALSE

Value

Invisible TRUE indicating successful synchronization.

Details

  • For common files:

    • If comparing by date only (by_date = TRUE): Copy files that are newer in the left directory to the right directory.

    • If comparing by date and content (by_date = TRUE and by_content = TRUE): Copy files that are newer and different in the left directory to the right directory.

    • If comparing by content only (by_content = TRUE): Copy files that are different in the left directory to the right directory.

  • Copy to the right directory those files that exist only in the left directory.

  • Delete from the right directory those files that are exclusive in the right directory (i.e., missing in the left directory)

Examples

# Create syncdr environment with toy directories
library(syncdr)
e <- toy_dirs()
#> ■■■■■■■■■■■■■■■                   47% | ETA:  5s
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■       87% | ETA:  1s

# Get left and right directories' paths
left  <- e$left
right <- e$right

# Synchronize by date & content
# Providing left and right paths to directories, as well as by_date and content
full_asym_sync_to_right(left_path  = left,
                        right_path = right,
                        by_date    = FALSE,
                        by_content = TRUE)
#> ✔ synchronized
#> 
# Providing sync_status object
#sync_status = compare_directories(left_path = left,
#                                   right_path = right)
#full_asym_sync_to_right(sync_status = sync_status)