Read ONLY x lines from a txt file with a windows batch file

前端 未结 2 1962
小蘑菇
小蘑菇 2021-01-24 05:20

How can I read only X lines from a a.txt file?

The file contains all the names of a directory, I would like to read only x lines. X can be a number that can varies from

2条回答
  •  既然无缘
    2021-01-24 06:07

    You'll need to modify this based on your needs, but the script below will loop through the file 'directories.txt', and ECHO the contents of the line until you hit the maximum number of lines set in maxlines.

    @ECHO OFF
    setlocal enabledelayedexpansion
    
    SET /A maxlines=1
    SET /A linecount=0
    
    FOR /F %%A IN (directories.txt) DO ( 
      IF !linecount! GEQ %maxlines% GOTO ExitLoop
      ECHO %%A 
      SET /A linecount+=1
    )
    
    :ExitLoop
    
    PAUSE
    

提交回复
热议问题