R/get.files.r

Defines functions get.files

Documented in get.files

#' This function returns the paths of all files a given folder
#'
#' @param folder.path The path of the folder 
#' @param recursive Search for files in subfolders. Defaults to FALSE
#' @return A list of file paths
#' @examples
#' get.files("./path/to/folder") 
get.files <- function(folder.path, recursive=FALSE) {
    all.files <- paste(folder.path, list.files(folder.path), sep='/')
    folders <- list.dirs(folder.path)
    folders <- setdiff(folders, folder.path)
        if (recursive & length(folders) > 0) {
        for (folder in folders) {
            fls <- paste(folder, list.files(folder), sep='/')
            fls <- fls[file.info(fls)$size > 0]
            all.files <- c(all.files, fls)
            }
        }
    all.files <- all.files[file.info(all.files)$size > 0 & !(file.info(all.files)$isdir)]
    return(all.files)
}    
michalmonselise/read.folder documentation built on May 22, 2019, 9:53 p.m.