Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_dir_empty function #472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export(fs_perms)
export(group_ids)
export(is_absolute_path)
export(is_dir)
export(is_dir_empty)
export(is_file)
export(is_file_empty)
export(is_link)
Expand Down
21 changes: 21 additions & 0 deletions R/is.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,24 @@ is_absolute_path <- function(path) {
tidy_path <- path_tidy(path)
grepl("^~", path) | grepl("^(/+|[A-Za-z]:)", tidy_path)
}

#' Check if a directory is empty
#'
#' This function checks whether a given directory is empty or not.
#'
#' @param path A character string specifying the path to the directory to check.
#'
#' @return A logical value. Returns \code{TRUE} if the directory is empty,
#' \code{FALSE} otherwise.
#'
#' @examples
#' \dontrun{
#' is_dir_empty("path/to/empty/directory") # Returns TRUE
#' is_dir_empty("path/to/non-empty/directory") # Returns FALSE
#' }
#'
#' @export
is_dir_empty <- function(path) {
length(dir_ls(path)) == 0
}

1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ reference:
- title: Helpers
contents:
- is_file
- is_dir_empty
- as_fs_path
- as_fs_bytes
- as_fs_perms
Expand Down
25 changes: 25 additions & 0 deletions man/is_dir_empty.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading