title: Loop: Convert many .txt to .csv in single directory [Using R]
body: <p>Probably a pretty simple answer but I've had trouble converting a bunch of .txt files to .csv files in a loop. I don't want to merge or append them, just convert 71 individual .txt files into 71 individual .csv files. </p>
  
  <p>I was doing my best to refer to other questions with my code relying on this thread:
  <a href="https://stackoverflow.com/questions/35238391/create-a-loop-convert-txt-to-csv-in-r">create a loop: convert .txt to .csv in R</a></p>
  
  <p>I was adapting it and this is what I have so far:</p>
  
  <pre><code>filelist = list.files(pattern = ".txt")
  
   for (i in 1:length(filelist)) {
    cur.input.file &lt;- filelist[i]
    cur.output.file &lt;- paste0(cur.input.file, ".csv") 
    print(paste("Processing the file:", cur.input.file))
  
    # If the input file has less than 11 rows you will reveive the error message:
    # "Error in read.table: no lines available in input")
    data = read.delim(cur.input.file, header = TRUE)
    write.table(data, file=cur.output.file, sep=",", col.names=TRUE, row.names=FALSE)
  }
  </code></pre>
  
  <p>However, my results are coming out with:</p>
  
  <pre><code>[1] "Processing the file: filename1.txt.txt"
  [1] "Processing the file: filename2.txt.txt"
  [1] "Processing the file: filename3.txt.txt"
  [1] "Processing the file: filename4.txt.txt"
  [1] "Processing the file: filename5.txt.txt"
  </code></pre>
  
  <p>and the formatting is all screwed up.</p>
  
  <p>Any advice/ what am I doing wrong?</p>
  
  <p>Cheers and Thank you.</p>