Convert Text File

2017/04/09

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 = "")
  
  
}