| 1. |
Solve : DOS Viewing of Number of Lines from end of file!? |
|
Answer» I have a small BATCH file that counts total lines in a file then use more to display from the calculated value. But I would LIKE loop this batch file to display all files in a given folder to the screen or to a file! Can't figure out how to loop thru every file in a folder! But I'm unable to process more than one file at a time. So I'm really displaying the last 5 lines of each file. What is it that you really want to do?I have a small batch file that counts total lines, subtract a inputted value (5), then use more to display from that line number to the end of file to the screen or file. But I would like loop this batch file (below) to work on all files in a folder Can't figure out how to loop thru multiple files in a folder! ( The code below works fine for a single file, I just need to do more then one at a time ) Help!!!!!!!! Example Below: @echo off cls setlocal :: Syntax: %1 = displayed Lines :: %2 = path and input filename. :: EX: eof 10 \Input_filename.txt ( wildcards may be used ) If {%1} equ {} echo %%1 Missing Data - Re-Enter&&exit /b If {%2} equ {} echo %%2 Missing Data - Error Data Missing&&exit /b :@echo on :start set infile=%2 for /f "tokens=3" %%A in ('find /v /c "@[emailprotected]" %infile%') do ( set lines=%%A ) set /a count=%lines%-%1 More +%count% %infile% :@echo * * * Total Lines in %infile% = %lines% * * * :endThis will process every *.txt filename in the folder It enables delayed expansion within the loop so that filenames with ! in them are processed too. Code: [Select]@echo off for %%a in (*.txt) do ( "set file=%%a" setlocal enabledelayedexpansion echo filename=!file! endlocal pause )OK, Where do I put my code? I guess I'm not quite sure how to interface the two pieces! Thanks Again for all your help! Code: [Select]@echo off if "%~2"=="" ( echo Lists the number of lines from the end of files echo Syntax: %0 NumberOfLines "d:\path\filespec" echo. echo example: %0 5 *.txt echo example: %0 3 "c:\my files folder\*.txt" pause goto :EOF ) setlocal enabledelayedexpansion for %%a in ("%~2") do ( for /f %%b in ('find /v /c "" ^< "%%a" ') do set "lines=%%b" set /a count=lines-%~1 if !count! GTR 0 More +!count! "%%a" ) pausePerfect! Now just trying to figure out why it works! Thanks sooooooooo Much! You're welcome. |
|