Compare Two Directories for Synchronization Status
compare_directories.Rd
This function compares two directories, typically referred to as 'left' and 'right', to determine their synchronization status at the file level. The primary goal is to identify the synchronization status of files present in both directories and those exclusive to either directory.
Usage
compare_directories(
left_path,
right_path,
recurse = TRUE,
by_date = TRUE,
by_content = FALSE,
verbose = getOption("syncdr.verbose")
)
Arguments
- left_path
Path to the left/first directory.
- right_path
Path to the right/second directory.
- recurse
If TRUE, fully recurses through subdirectories. If a positive integer, specifies the number of levels to recurse.
- by_date
Logical. If TRUE (default), compares directories based on the modification date of common files.
- by_content
Logical. If TRUE, compares directories based on the hashed content of common files. Default is FALSE
- verbose
Logical. If TRUE display additional info on the comparison process. Default is FALSE
Value
A list of class "syncdr_status" containing the following elements:
Non-common files: Paths and synchronization status of files exclusive to either directory.
Common files: Paths and synchronization status of files present in both directories.
Path of the left directory.
Path of the right directory.
Sync Status Types
The synchronization status is determined for files present in both directories, as well as for files exclusive to either directory. It can be computed based on modification date only, content only, or both.
For Common Files:
When comparing by date: 'new', 'old', or 'same'.
When comparing by date and content: 'new and different', 'new and same', 'old and different', 'old and same', 'same and different', or 'same and same'.
When comparing by content only: 'different' or 'same'.
For Non-Common Files:
When comparing by date (or by date and content, or by content only): 'only in left' or 'only in right'.
Examples
# Compare directories with 'compare_directories()'
e <- toy_dirs()
#> ■■■■■■■■■ 27% | ETA: 8s
#> ■■■■■■■■■■■■■■■■■■■ 60% | ETA: 5s
# Get left and right directories' paths
left <- e$left
right <- e$right
compare_directories(left, right)
#>
#> ── Synchronization Summary ─────────────────────────────────────────────────────
#> • Left Directory: /tmp/RtmpNpo9CP/left
#> • Right Directory: /tmp/RtmpNpo9CP/right
#> • Total Common Files: 7
#> • Total Non-common Files: 9
#> • Compare files by: date
#>
#> ── Common files ────────────────────────────────────────────────────────────────
#> path modification_time_left modification_time_right modified
#> 1 /left/B/B1.Rds 2024-11-04 20:16:24 2024-11-04 20:16:25 right
#> 2 /left/B/B2.Rds 2024-11-04 20:16:27 2024-11-04 20:16:28 right
#> 3 /left/C/C1.Rds 2024-11-04 20:16:25 2024-11-04 20:16:31 right
#> 4 /left/C/C2.Rds 2024-11-04 20:16:28 2024-11-04 20:16:29 right
#> 5 /left/C/C3.Rds 2024-11-04 20:16:30 2024-11-04 20:16:31 right
#> 6 /left/D/D1.Rds 2024-11-04 20:16:27 2024-11-04 20:16:26 left
#> 7 /left/D/D2.Rds 2024-11-04 20:16:30 2024-11-04 20:16:29 left
#>
#> ── Non-common files ────────────────────────────────────────────────────────────
#>
#> ── Only in left ──
#>
#> # A tibble: 4 × 1
#> path_left
#> <fs::path>
#> 1 /left/A/A1.Rds
#> 2 /left/A/A2.Rds
#> 3 /left/A/A3.Rds
#> 4 /left/B/B3.Rds
#>
#> ── Only in right ──
#>
#> # A tibble: 5 × 1
#> path_right
#> <fs::path>
#> 1 /right/C/C1_duplicate.Rds
#> 2 /right/D/D3.Rds
#> 3 /right/E/E1.Rds
#> 4 /right/E/E2.Rds
#> 5 /right/E/E3.Rds
# Compare by date and content
compare_directories(left, right, by_content = TRUE)
#>
#> ── Synchronization Summary ─────────────────────────────────────────────────────
#> • Left Directory: /tmp/RtmpNpo9CP/left
#> • Right Directory: /tmp/RtmpNpo9CP/right
#> • Total Common Files: 7
#> • Total Non-common Files: 9
#> • Compare files by: date & content
#>
#> ── Common files ────────────────────────────────────────────────────────────────
#> path modification_time_left modification_time_right modified
#> 1 /left/B/B1.Rds 2024-11-04 20:16:24 2024-11-04 20:16:25 right
#> 2 /left/B/B2.Rds 2024-11-04 20:16:27 2024-11-04 20:16:28 right
#> 3 /left/C/C1.Rds 2024-11-04 20:16:25 2024-11-04 20:16:31 right
#> 4 /left/C/C2.Rds 2024-11-04 20:16:28 2024-11-04 20:16:29 right
#> 5 /left/C/C3.Rds 2024-11-04 20:16:30 2024-11-04 20:16:31 right
#> 6 /left/D/D1.Rds 2024-11-04 20:16:27 2024-11-04 20:16:26 left
#> 7 /left/D/D2.Rds 2024-11-04 20:16:30 2024-11-04 20:16:29 left
#> sync_status
#> 1 different content
#> 2 different content
#> 3 same content
#> 4 different content
#> 5 different content
#> 6 different content
#> 7 different content
#>
#> ── Non-common files ────────────────────────────────────────────────────────────
#>
#> ── Only in left ──
#>
#> # A tibble: 4 × 1
#> path_left
#> <fs::path>
#> 1 /left/A/A1.Rds
#> 2 /left/A/A2.Rds
#> 3 /left/A/A3.Rds
#> 4 /left/B/B3.Rds
#>
#> ── Only in right ──
#>
#> # A tibble: 5 × 1
#> path_right
#> <fs::path>
#> 1 /right/C/C1_duplicate.Rds
#> 2 /right/D/D3.Rds
#> 3 /right/E/E1.Rds
#> 4 /right/E/E2.Rds
#> 5 /right/E/E3.Rds
# Compare by content only
compare_directories(left, right, by_content = TRUE, by_date = FALSE)
#>
#> ── Synchronization Summary ─────────────────────────────────────────────────────
#> • Left Directory: /tmp/RtmpNpo9CP/left
#> • Right Directory: /tmp/RtmpNpo9CP/right
#> • Total Common Files: 7
#> • Total Non-common Files: 9
#> • Compare files by: content
#>
#> ── Common files ────────────────────────────────────────────────────────────────
#> path sync_status
#> 1 /left/B/B1.Rds different content
#> 2 /left/B/B2.Rds different content
#> 3 /left/C/C1.Rds same content
#> 4 /left/C/C2.Rds different content
#> 5 /left/C/C3.Rds different content
#> 6 /left/D/D1.Rds different content
#> 7 /left/D/D2.Rds different content
#>
#> ── Non-common files ────────────────────────────────────────────────────────────
#>
#> ── Only in left ──
#>
#> # A tibble: 4 × 1
#> path_left
#> <fs::path>
#> 1 /left/A/A1.Rds
#> 2 /left/A/A2.Rds
#> 3 /left/A/A3.Rds
#> 4 /left/B/B3.Rds
#>
#> ── Only in right ──
#>
#> # A tibble: 5 × 1
#> path_right
#> <fs::path>
#> 1 /right/C/C1_duplicate.Rds
#> 2 /right/D/D3.Rds
#> 3 /right/E/E1.Rds
#> 4 /right/E/E2.Rds
#> 5 /right/E/E3.Rds