copy_files_to_target_dir: Copy Files to Flat Structure

Description Usage Arguments Examples

View source: R/function.R

Description

Calls file.copy under the hood but gives a message about the indices and paths of the files that could not be copied.

Usage

1
copy_files_to_target_dir(from_paths, target_dir, target_files)

Arguments

from_paths

paths to the files to be copied

target_dir

path to the target directory

target_files

relative paths to the target files, relative to target_dir

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root <- system.file(package = "kwb.file")

relative_paths <- dir(root, recursive = TRUE)

# The original files are in root or in different subfolders
relative_paths

# Create a temporary target folder
target_dir <- kwb.utils::createDirectory(file.path(tempdir(), "target"))

# 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)

KWB-R/kwb.file documentation built on Dec. 31, 2021, 8:15 p.m.