list.files - exclude folder

Use regex - grepl to exclude:

# find all ".txt" files
myfiles <- list.files(path = ".", pattern = ".txt",
                      full.names = TRUE, recursive = TRUE)

# exclude unfinished stuff
myfilesfinished <- myfiles[ !grepl("unfinished_stuff", myfiles) ]

Building upon @zx8754's answer, just with tidyverse approach using %>%:

library(tidyverse)

list.files(path=".", pattern=".txt", full.names = TRUE, recursive=TRUE) %>%
   stringr::str_subset(., "unfinished_stuff", negate = TRUE)

Tags:

Regex

R