Skip to contents

Use with caution. Remove files that match suffix from one or more directories. This is intended to clean output files created by resmush_file() or resmush_dir().

Usage

resmush_clean_dir(dir, suffix = "_resmush", recursive = FALSE)

Arguments

dir

A character vector of directory paths. See the path argument of list.files().

suffix

A character string containing the suffix pattern used to identify files. The value is interpreted as a regular expression. The default is "_resmush", the default suffix used by resmush_file().

recursive

Logical. Should the file search recurse into directories?

Value

An invisible() NULL. Messages list the files selected for removal.

See also

resmush_file() and resmush_dir() create the suffixed output files that this function removes.

Examples

# \donttest{
# Create a temporary file with a suffix to remove.
png_file <- system.file("extimg/example.png", package = "resmush")
suffix <- "_would_be_removed"
tmp_png <- file.path(
  tempdir(),
  paste0("example", suffix, ".png")
)

file.exists(tmp_png)
#> [1] FALSE
file.copy(png_file, tmp_png, overwrite = TRUE)
#> [1] TRUE

file.exists(tmp_png)
#> [1] TRUE

# Run with the default suffix. This should not remove the file.
resmush_clean_dir(tempdir())
#>  No files with suffix "_resmush" found in /tmp/Rtmp8qRcZC.

file.exists(tmp_png)
#> [1] TRUE

# Use the matching suffix to remove the file.
resmush_clean_dir(tempdir(), suffix = suffix)
#>  Removing 1 file:
#>/tmp/Rtmp8qRcZC/example_would_be_removed.png

file.exists(tmp_png)
#> [1] FALSE
# }