Calls file.copy
under the hood but gives a message about the indices
and paths of the files that could not be copied.
copy_files_to_target_dir(from_paths, target_dir, target_files)
paths to the files to be copied
path to the target directory
relative paths to the target files, relative to
target_dir
root <- system.file(package = "kwb.file")
relative_paths <- dir(root, recursive = TRUE)
# The original files are in root or in different subfolders
relative_paths
#> [1] "DESCRIPTION" "INDEX"
#> [3] "LICENSE" "Meta/Rd.rds"
#> [5] "Meta/features.rds" "Meta/hsearch.rds"
#> [7] "Meta/links.rds" "Meta/nsInfo.rds"
#> [9] "Meta/package.rds" "NAMESPACE"
#> [11] "NEWS.md" "R/kwb.file"
#> [13] "R/kwb.file.rdb" "R/kwb.file.rdx"
#> [15] "extdata/setup_package.R" "help/AnIndex"
#> [17] "help/aliases.rds" "help/kwb.file.rdb"
#> [19] "help/kwb.file.rdx" "help/paths.rds"
#> [21] "html/00Index.html" "html/R.css"
# Create a temporary target folder
target_dir <- kwb.utils::createDirectory(file.path(tempdir(), "target"))
#> The directory "/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//Rtmperz4mr/target" was created.
# Copy all files into one target folder without subfolders
from_paths <- file.path(root, relative_paths)
to_paths <- basename(from_paths)
# Make sure that the target file names contain no duplicates, otherwise
# an error is raised
to_paths <- kwb.utils::makeUnique(to_paths, warn = FALSE)
# Copy the files
copy_files_to_target_dir(from_paths, target_dir, to_paths)
# Look at the result
dir(target_dir, recursive = TRUE)
#> [1] "00Index.html" "AnIndex" "DESCRIPTION" "INDEX"
#> [5] "LICENSE" "NAMESPACE" "NEWS.md" "R.css"
#> [9] "Rd.rds" "aliases.rds" "features.rds" "hsearch.rds"
#> [13] "kwb.file" "kwb.file.rdb" "kwb.file.rdb.1" "kwb.file.rdx"
#> [17] "kwb.file.rdx.1" "links.rds" "nsInfo.rds" "package.rds"
#> [21] "paths.rds" "setup_package.R"