从阅读txt文件只适用于X线,Windows批处理文件 [英] Read ONLY x lines from a txt file with a windows batch file

查看:129
本文介绍了从阅读txt文件只适用于X线,Windows批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从一个A.TXT文件中读取只适用于X线?

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

该文件包含一个目录的所有的名字,我想只读x行。
X可以是一个数字,可以从1变化到99

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 1 to 99

推荐答案

您需要根据您的需求来修改这一点,但通过下面的文件'directories.txt将循环剧本,和回声的内容行,直到你打在的maxlines 设置的行的最大数量。

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

这篇关于从阅读txt文件只适用于X线,Windows批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆