0

I have two files that come in daily to a shared drive. When they are posted, they come in with the current date as part of the file name. example ( dataset1_12517.txt and dataset2_12517.txt) the next day it posts it will be (dataset1_12617.txt and so on). They are pipe delimited files if that matters.

I am trying to automate a daily merge of these two files to a single excel file that will be overwritten with each merge (file name remains the same) so my tableau dashboard can read the output without having to make a new connection daily. The tricky part is the file names will change daily, but they follow a specific naming convention.

I have access to R Studio. I have not started writing code yet so looking for a place to start or a better solution.

  • Does is have to merge into an Excel file or can you use it if they are merged into a single txt file? And does it have to be a solution that uses R to do the merging or are you open to alternatives, such as Windows batch files? – Sam M Dec 06 '17 at 06:06

1 Answers1

2

On a Window machine, use the copy or xcopy command lines. There are several variations on how to do it. The jist of it though is that if you supply the right switches, the source file will append to the destination file.

I like using xcopy for this. Supply the destination file name and then a list of source files.

This becomes a batch file and you can run it as a scheduled task or on demand.

This is roughly what it would look it. You may need to check the online docs to choose the right parameter switches.

xcopy C:\SRC\souce_2010235.txt newfile.txt /s

As you play with it, you may even try using a wildcard approach.

xcopy C:\SRC\*.txt newfile.txt /s

See Getting XCOPY to concatenate (append) for more details.

Sam M
  • 4,136
  • 4
  • 29
  • 42