How to obtain a list of directories within a directory, like list.files(), but instead “list.dirs()”

后端 未结 7 619
梦如初夏
梦如初夏 2021-01-30 12:14

This may be a very easy question for someone - I am able to use list.files() to obtain a list of files in a given directory, but if I want to get a list of director

7条回答
  •  一整个雨季
    2021-01-30 12:53

    list.dirs <- function(...) {
        x <- dir(...)
        x[file_test("-d", x)]
    }
    

    might be of use?

    How might we do this recursively? (the recursive argument of dir breaks these functions because it never returns directory names, just the files within each directory, etc...).

提交回复
热议问题