Solved

How to combine txt files and change .txt extension

Posted on 2016-09-22
7
41 Views
Last Modified: 2016-09-23
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
Comment
Question by:brasiman
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:NVIT
ID: 41811538
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
 

Author Comment

by:brasiman
ID: 41812572
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
 
LVL 23

Accepted Solution

by:
NVIT earned 500 total points
ID: 41812639
@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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:brasiman
ID: 41813134
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
 
LVL 23

Expert Comment

by:NVIT
ID: 41813149
Hi brasiman.

Please close this question. I'll help you with the next one. In that one, add a link to this page.
0
 

Author Comment

by:brasiman
ID: 41813157
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
 

Author Closing Comment

by:brasiman
ID: 41813160
Perfect! Replied quickly. Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now