I have several thousand .txt files in a directory and would like to read them all into tidytext where I would then add columns of metadata. The filenames themselves contain all of the metadata and I have been successful in using substr to parse the different pieces location, time, date, etc. of the one file, but I cannot find an example of how I might proceed to do this for all of the files in the directory.
For example, I have the .txt files:
FFTJan141138
FFTJan151136
FFTJan161151
FFTJan171144
I have managed read the files from my wd into a tibble using:
tbl <- list.files(pattern = "*.txt") %>%
map_chr(~ read_file(.)) %>%
data_frame(text = .)
What I need help with is inserting some data columns that correspond to the metadata in the file names.
For example, for the first file named: FFTJan141138 I now have the tibble whose row for this file has one column for the contents of FFTJan141138. I would like to add to this row four additional columns that include FFT, JAN, 14, and 1138. I can parse the text in the file names with substr, but don't know how to do this as the data is read into tidytext. Any help would be appreciated.
Thanks.