Link to home
Start Free TrialLog in
Avatar of Halia
HaliaFlag for United States of America

asked on

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!
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
revising my first script to include "Records in file"

@echo %%F %%C Records in file
Avatar of Halia

ASKER

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?
add the following line to the bottom of the script:

exit
Avatar of Halia

ASKER

Thank you so much!!!!!  You have just saved hours of cutting and pasting!