• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

Batch File to return text file name & data

Hello,

I need a Batch file that will produce a text that will have the name of the file and the data (all the files have 1 line only)

Example - ProdCount.txt has 1 record in it that tells me a count of the Prod.txt file (54000 records in file)

So my output would be...

ProdCount.txt 54000 Records in File
EmpInfo.txt 170000 in file
etc.

Any suggestions?

Thanks in advance,

Trish

Hope I have this in the right zone!
0
Halia
Asked:
Halia
  • 4
  • 2
1 Solution
 
Ron MalmsteadInformation Services ManagerCommented:
You can use FINDSTR


If the file only has one line, and you just want to return it's contents...

FINDSTR . C:\path\filename.txt
0
 
knightEknightCommented:
This will echo the filename first, but it assumes that ALL .txt files in the current directory have only one line of content:

  @echo off
  for %%F in (*.txt) do for /f "delims=" %%C in ('type %%F') do @echo %%F %%C

you can then re-direct the output of this file to a new file like this:

  mybat.bat > myout.txt
0
 
knightEknightCommented:
Actually the FINDSTR approach is easier, but you need to specify a wildcard in order to get the filename as part of the output:

FINDSTR . C:\path\*.txt > myout.txt
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
knightEknightCommented:
revising my first script to include "Records in file"

@echo %%F %%C Records in file
0
 
HaliaAuthor Commented:
Ok....this is working -

@echo off
  for %%F in (*.count) do for /f "delims=" %%C in ('type %%F') do @echo %%F %%C
Count.bat > Counts.txt

I get my file (PERFECT) but the Window is staying open.  I see the last record and it stops and sits there.

What do I need to change?
0
 
knightEknightCommented:
add the following line to the bottom of the script:

exit
0
 
HaliaAuthor Commented:
Thank you so much!!!!!  You have just saved hours of cutting and pasting!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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