celestialgod

print tree with R

Mar 11th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.54 KB | None | 0 0
  1. library(magrittr)
  2. library(stringr)
  3. print_dir_f <- function(pathName, layer){
  4.   fileNames <- list.files(pathName)
  5.   isdir <- file.info(fileNames)$isdir
  6.   isdir[is.na(isdir)] <- FALSE
  7.   for (i in seq_along(fileNames))
  8.   {
  9.     if (isdir[i])
  10.     {
  11.       str_c(rep("  ", layer), collapse = "") %>% str_c(fileNames[i], '\n') %>% cat
  12.       str_c(pathName, fileNames[i], sep='/') %>% print_dir_f(layer+1)
  13.     } else
  14.     {
  15.       str_c(rep("  ", layer), collapse = "") %>% str_c(fileNames[i], '\n') %>% cat
  16.     }
  17.   }
  18. }
  19. print_dir_f(".", 0)
Add Comment
Please, Sign In to add comment