build_folders_from_file: Create Folder Structure from Paths in File

View source: R/build_folders_from_file.R

build_folders_from_fileR Documentation

Create Folder Structure from Paths in File

Description

Create Folder Structure from Paths in File

Usage

build_folders_from_file(
  file,
  target_dir,
  pattern = NULL,
  max_depth = NULL,
  encoding = "Latin-1"
)

Arguments

file

path to file containing path strings

target_dir

path to target directory in which to create the folder structure

pattern

regular expression matching the paths from file to be considered

max_depth

maximum folder depth to be considered

encoding

encoding used when reading file

Examples

# Create a vector of example paths
paths <- c("a1/b1", "a1/b2", "a2/b1", "a2/b1/c1")

# Write the example paths to a temporary file
writeLines(paths, file <- tempfile())

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

# Create the folder structure as defined by the paths in the temporary file
kwb.fakin::build_folders_from_file(file, target_dir)

# List the directory paths below the target directory
paths_reread <- list.dirs(target_dir, recursive = TRUE, full.names = FALSE)

# Stop if not all paths have been created
stopifnot(all(paths %in% paths_reread))


KWB-R/kwb.fakin documentation built on June 14, 2022, 2 p.m.