Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 107
  • Last Modified:

How to combine txt files and change .txt extension

I have multiple .txt files in one folder. Each .txt file has a few rows of data. How would I create a batch file that will combine the rows on all the text files into one .txt file. So if there are 5 .txt files and 2 rows in each of those text files, the new .txt file would have 10 rows of data. Also, when this new file is created, I need the file extension to be ".tra". The file name can be "TR2016" Is there a way to do this? Thanks!
0
brasiman
Asked:
brasiman
  • 4
  • 3
1 Solution
 
NVITCommented:
Note: You have not specified if the files must be output in a certain order. e.g. file1.txt, file2.txt, etc. If so, code must be revised.

Make a .bat file of this.
Change FNSrcPatt, and FNOut values per your needs.

@echo off
setlocal enabledelayedexpansion

set FNSrcPatt=c:\local\test\*.txt
set FNOut=TR2016.tra
for %%a in ("%FNSrcPatt%") do (type %%a>>"%FNOut%")

Open in new window

0
 
brasimanAuthor Commented:
Thank you NVIT! This is perfect! One thing I forgot to ask, what if I want to move the .tra file to a different location? So the .txt files are in c:\folder and i want to create the .tra file in the c:\TRA_Files.
0
 
NVITCommented:
@echo off
setlocal enabledelayedexpansion

set FNSrcPatt=c:\folder\*.txt
set FNOut=c:\TRA_Files\TR2016.tra
for %%a in ("%FNSrcPatt%") do (type %%a>>"%FNOut%")

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
brasimanAuthor Commented:
NVIT, thats perfect. Thank. I just ran into the last thing with this. And if i need to start another question I can. When I run this, the old .txt files are left behind in c:\folder\. Is there a way, keeping the script as is, just adding a way for me to specify a folder that those .txt files are put...and have a folder created with it date and time stamped? So, using what you suggested, but then adding code where I specify where to create a new folder, the title of the folder is the current date and time, then the .txt files are moved to the newly created folder. Does that make sense? Thanks!
0
 
NVITCommented:
Hi brasiman.

Please close this question. I'll help you with the next one. In that one, add a link to this page.
0
 
brasimanAuthor Commented:
Hi NVIT, I'll close this one now. Here's the link to the new question:
https://www.experts-exchange.com/questions/28972004/How-to-combine-txt-and-create-a-new-folder.html
0
 
brasimanAuthor Commented:
Perfect! Replied quickly. Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now