I'd like to try and pull all files in my working directory that don't begin with the string "CONVERTED" -- so I'd like for list.files()
to find "x.csv" but not "CONVERTEDx.csv" (my program will write a .csv file later that has that naming convention).
I tried:
x <- list.files(pattern = "^(!CONVERTED)*.csv")
This creates an empty character variable.
grep
would come in handy on this one to get the files that do not match the pattern instead of trying to get all files and then filter in more than one line. invert
gives the opposite of the pattern. value
gives the filenames that do not match the pattern
.
x <- grep(list.files(pattern="\\.csv"), pattern='^CONVERTED', invert=TRUE, value=TRUE)