R/remove_empty_parents.R

Defines functions remove_empty_parents

Documented in remove_empty_parents

#' remove_empty_parents
#' @param path path
#' @param root root
#'
remove_empty_parents <- function(path, root) {
  root <- gsub("/", "", root)
  directory <- dirname(path)
  continue <- directory != root

  while (continue) {
    empty <- length(dir(directory)) == 0
    if (empty) {
      unlink(directory, recursive = TRUE)
      directory <- dirname(directory)
      continue <- directory != root
    } else {
      continue <- FALSE
    }
  }
  invisible(TRUE)
}

Try the rDataPipeline package in your browser

Any scripts or data that you put into this service are public.

rDataPipeline documentation built on Nov. 18, 2021, 1:14 a.m.