We help IT Professionals succeed at work.

Batch File to return text file name & data

Halia
Halia asked
on
393 Views
Last Modified: 2012-05-11
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!
Comment
Watch Question

Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT

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

@echo %%F %%C Records in file

Author

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?
CERTIFIED EXPERT

Commented:
add the following line to the bottom of the script:

exit

Author

Commented:
Thank you so much!!!!!  You have just saved hours of cutting and pasting!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.