Learn R Programming

evanverse (version 0.3.7)

file_tree: file_tree: Print and Log Directory Tree Structure

Description

Print the directory structure of a given path in a tree-like format using ASCII characters for maximum compatibility across different systems. Optionally, save the result to a log file for record keeping or debugging.

Usage

file_tree(
  path = ".",
  max_depth = 2,
  verbose = TRUE,
  log = FALSE,
  log_path = NULL,
  file_name = NULL,
  append = FALSE
)

Value

Invisibly returns a character vector containing each line of the file tree.

Arguments

path

Character. The target root directory path to print. Default is ".".

max_depth

Integer. Maximum depth of recursion into subdirectories. Default is 2.

verbose

Logical. Whether to print the tree to console. Default is TRUE.

log

Logical. Whether to save the tree output as a log file. Default is FALSE.

log_path

Character. Directory path to save the log file if log = TRUE. Default is tempdir().

file_name

Character. Custom file name for the log file. If NULL, a name like "file_tree_YYYYMMDD_HHMMSS.log" will be used.

append

Logical. If TRUE, appends to an existing file (if present). If FALSE, overwrites the file. Default is FALSE.

Examples

Run this code
# Basic usage with current directory:
file_tree()
file_tree(".", max_depth = 3)

# \donttest{
# Example with temporary directory and logging:
temp_dir <- tempdir()
file_tree(temp_dir, max_depth = 2, log = TRUE, log_path = tempdir())
# }

Run the code above in your browser using DataLab