Convert Text File

A quick piece of code that reads a text file, changes something, saves a new text file, and iterates that process for every text file in that folder.

setwd("path to the text files")
library(readr)

all_files = Sys.glob("*.txt")



for(i in 1:length(all_files)){
  
  data = all_files[i]
  mystring = read_file(paste(data))
  
  new_data = gsub("old piece of text", "new piece of text", mystring)
  
  write_file(new_data, path = paste("something", code, ".txt", sep = "")
  
  
}

Bo\(^2\)m =)