Search code examples
r

Delete empty folders inside working directory


I have number of empty folders inside a working directory. Want to remove those empty folders in R. Can somebody help me out on this.


Solution

  • Assuming the current directory is the one in which you want to delete the empty folders, you can do:

    folders <- list.dirs(recursive = FALSE)
    for(folder in folders){
      if(length(dir(folder)) == 0){
        unlink(folder, recursive = TRUE)
      }
    }