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.
Finding Non-Empty Files Only Under the Given Directory As we've learned, find will search recursively under the given directory by default. If we want the find command only to scan the given directory, we can pass the -maxdepth 1 option.
For empty directories, use rmdir [dirname] or rm -d [dirname] For non-empty directories, use rm -r [dirname]
Empty dirs in current dir: find . -type d -empty . In addition, empty files: find . -type f -empty in current dir and deeper.
The non-empty directory means the directory with files or subdirectories. We can delete the directory by using the Delete() method of the Directory class.
Use the 'find' command along with the '-type' flag that specifies the directory type search using the keyword 'd'. The word '-empty' has been used as a flag to search only empty directories within the home directory as stated below. The dot means the current location which is the home directory of a Linux-based system.
Get filenames then extract directory name:
unique(dirname(list.files(full.names = TRUE, recursive = TRUE)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With