I want to list all *.tif files in directories that contain specific numeric values.
Example:
Path_source <- "C:/Files/"
Within this folder, I have 1000 folders, each named jobXXX
where XXX
stands for numeric value 1-999. So there is a folder job0
, job1
, ... , job999
.
Within each jobXXX
folder I have other folders and files. From this structure of folders I want to extract all files with the following pattern:
Year <- 2021
file.ls <- list.files(path=Path_source, pattern=paste0("Text_",Year,".*\\.tif"),all.files = TRUE, full.names = TRUE, recursive = TRUE)
So my missing element is now to filter the directories for folders with specific job numbers:
jobs <- c(1,14,45,67,129,834)
Example outcome:
> file.ls
[1] "C:/Files/job14/folder12/Text_2021_anothertext_abc.tif"
[2] "C:/Files/job45/folder81/Text_2021_anothertext_efg.tif"
Which function should I use?
Thank you