Skip to contents

This function checks if all filenames in a given vector use a specified separator consistently and return FALSE if there's any inconsistency.

Usage

validate_filenames(filenames, separator)

Arguments

filenames

A character vector of filenames to validate.

separator

A character string specifying the separator to check for. Valid options are "hyphen", "underscore", or "space".

Value

A logical value indicating whether all filenames use the specified separator consistently. Returns FALSE if any inconsistency is found.

Examples

# Test case for inconsistent separator usage
filenames <- c("file name-1.txt", "file name 2.csv", "file name 3.doc")
validate_filenames(filenames, "space") # Should return FALSE
#> [1] FALSE

filenames <- c("file-name-1.txt", "file_name-2.csv", "file_name-3.doc")
validate_filenames(filenames, "underscore") # Should return TRUE
#> [1] FALSE

filenames <- c("file-name-1.txt", "file_name-2.csv", "file name-3.doc")
validate_filenames(filenames, "underscore") # Should return FALSE
#> [1] FALSE