I have some files in the directory and their extensions all same. I want list all files but later on would like to ignore some of the file names that contain certain strings. I tried grepl
using this answer using-r-to-list-all-files-with-a-specified-extension.
For instance in this example I would like exclude the files which contains 'B' in it. So tried,
file_names <- c('AA','BA','KK','CB')
files <- paste0(file_names,'.txt')
Filter_files <- files[-grepl('.*B.txt|.B*.txt', files)]
Filter_files
"BA.txt" "KK.txt" "CB.txt"
Interestingly only AA.txt
excluded!