I have files called
value<-c("ABC_Seed_1_0.csv", "ABC_Seed_1_1.csv", "ABC_Seed_10_0.csv", "ABC_Seed_10_1.csv") I would like to only find and delete files that belong to file: seed_1.tar.xz (i.e. find all files called ACB_Seed_1_*.csv)
Problem I have is that if I search for seed_1 I will also get seed_10. Is there a trick?
I've tried adding the "_" using paste0
#Available files value<-c("ABC_Seed_1_0.csv", "ABC_Seed_1_1.csv", "ABC_Seed_10_0.csv", "ABC_Seed_10_1.csv") library(dplyr) library(tidyr) #File to match against (minus extension) file<-c("seed_10.tar.xz") ListToDelete<- value %>% as_tibble %>% filter(value, stringr::str_detect(string = value, pattern = paste0(fixed(tools::file_path_sans_ext(file, compression = TRUE),ignore_case = TRUE),"_")) #Returns an empty tibble file.remove(ListToDelete)
stringr::word(), i.e.stringr::word(value, 3, sep = '_') == '1'grep("ABC_Seed_1_\\d+.csv", value, value = TRUE)