after receiving critics for not asking the question the right way, I have returned again with what I think is better way. I am trying to solve homework problem in which I have to write a batch file and I am stuck.
When this batch file is called in CMD it receives 4 parameters:
- (1) Path to some directory with \ at the end; example: C:\Users\PC\Desktop\
- (2) Extension of the file; example: txt
- (3) Some string; example: "ab"
- (4) An integer; example: 3
The purpose of this batch file is to find all files X with extension (2) on local directory and all subdirectories received by (1), which have more than (4) lines in them that have substring (3) and write in console next sentence:
"File X has more than (4) liens, more precise Y, which have substring (3)". Where X is full path of the file that fulfills those conditions and Y exact number of lines in which substring is found.
Input in console should be like this: myfile.bat C:\Users\PC\Desktop\ txt ab 3
My attempt of solving this was like this:
@echo off
for %%a in ('dir /s %1*.%2') do (
for /f "delims= " %%G in ('find /c "%3" ^<%%a') do (
set linecount=%%G
if %linecount% gtr %4 (
echo File %%a has more than %4 lines, more precisley %linecount% which have substring %3
)
)
)
Hope this time I've done it partially right.