I have a folder with multiple files containing records.
I want a windows batch script which will copy all the 'file names' into a single output file along with the count of records that are present in all the files.
Reference FIND Search for a text string in a file & display all the lines where it is found.
find /v /c "" *.* > result.txt
How it works
/v
inverts the search (so when we search for nothing we find all
lines) /c
counts matches""
match nothing*.*
search all files> result.txt
redirect outputLimitations
\r\n
\r
) This makes it of limited use in searching binary or XML file types.To remove the additional - and blank lines we can wrap the above command in a for
construct as follows:
for /f "usebackq tokens=2-3" %a in (`find /v /c "" *.*`) do echo %a %b >> result.txt
Thanks a lot for your responses. Adding to my original requirement, the scenario is that a folder gets created (in YYYYMMDD format) on daily basis at a particular location. This folder contains few files with/without records present in it.
Since this is on a daily basis, I will be using this batch file daily. And whenever I execute this batch file on any particular day, it should then check for the folder which will be created on that particular day and then give an output file which contains the file names and the record count
Is there any way to get this requirement?
For just a list of filenames:
dir * /b /s > files.txt