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
)
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
# Basic usage:
# file_tree()
# file_tree("my_directory", max_depth = 3)
# \donttest{
# Example with temporary directory
temp_dir <- tempdir()
file_tree(temp_dir, max_depth = 2, log = TRUE)
#>
#> ── Directory Tree: C:\Users\84241\AppData\Local\Temp\Rtmp2JNh68 ────────────────
#> +-- Rf533429a2ec2
#> +-- bslib-851fffe0abea530870c09a9e845717e1
#> | +-- bootstrap.bundle.min.js
#> | +-- bootstrap.bundle.min.js.map
#> | +-- bootstrap.min.css
#> | +-- font.css
#> | +-- fonts
#> +-- downlit
#> | +-- base
#> | +-- curl
#> | +-- devtools
#> | +-- remotes
#> | +-- utils
#> +-- file5334227d12b5
#> | +-- font.css
#> | +-- tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTN1OVgaY.woff2
#> | +-- tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTNFOVgaY.woff2
#> | +-- tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTNVOVgaY.woff2
#> | +-- tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTOVOVgaY.woff2
#> | +-- tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTOlOV.woff2
#> | +-- tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTPlOVgaY.woff2
#> +-- file5334446e1a8b
#> +-- file53345bfd780f
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hiA.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZBhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZFhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZJhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZNhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZthiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZxhiI2B.woff2
#> | +-- font.css
#> +-- file53347134f37
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hiA.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZBhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZFhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZJhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZNhiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZthiI2B.woff2
#> | +-- UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZxhiI2B.woff2
#> | +-- font.css
#> +-- file5334783b1c5b
#> +-- file5334f304a5
#> ✔ File tree log saved to: C:\Users\84241\AppData\Local\Temp\Rtmp2JNh68\logs\tree\file_tree_20250929_114409.log
# }