Aarón Gzz
Aarón Gzz

Reputation: 99

list.files pattern for specific word and file extension

I'm trying to list all files that include a specific word ("students") and file extension (".csv") in their file name. I want to do this through pattern but I must be doing something wrong.

# (1) Create File List
pat=paste("students","*\\.csv$")
csv_files <- list.files (path       = "R/win-library/Practice/Schoolprac/", 
                         pattern    = pat, 
                         recursive  = T,
                         full.names = T)

The file should include the word "students" and be a .csv file. What could I be doing wrong? Students doesn't need to be right before .csv nor at the beginning, just included. I'm not getting an error, just no results.

Upvotes: 1

Views: 396

Answers (1)

Waldi
Waldi

Reputation: 41220

try

   pattern = '.*students.*\\.csv$'

You can test regular expressions in R with this tester

Upvotes: 1

Related Questions