user2380782 user2380782 - 26 days ago 18
R Question

List non empty directories

Is there any easy way to list only directories that are not empty?

I am aware of

list.dirs
but I couldn't find the way to list only directories that are not empty.

Answer

You can use list.files on the result of list.dirs:

dirlist <- list.dirs("./R/R-3.3.1/library/zoo")
dirlist [sapply(dirlist, function(x) length(list.files(x))>0)]
Comments