方法一:
Bash@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /a-d/b/s *.txt') do (
for /f "tokens=3 delims=:" %%b in ('find /c /v "" "%%a"') do set n=%%b
ren "%%a" "%%~na_!n: =!%%~xa"
)
pause
方法二:
Bash@echo off & setlocal enabledelayedexpansion
%1(for /f "delims=" %%i in ('%~0 :^|sort') do ren %%i)& pause & exit /b
for /f "tokens=1,* delims= " %%i in ('find /c /v "" *.txt') do (
set info=%%j
set ln=!info:*:=!
for /f "delims=" %%a in ("!ln!") do set fn=!info::%%a=!
echo;"!fn!" "!fn:~,-4!!ln:~1!.txt"
)
批处理获取文件行数的方法
Bash@echo off
for /f "tokens=2 delims=:" %%a in ('find /c /v "" data.txt')do set/a result=%%a+0
echo,%result%
pause
以上方法其实都大同小异,执行效率也差不多,小伙伴们需要的话自行选择吧
出处:https://www.zhiu.cn/51620.html
=======================================================================================
@echo off
@setlocal
@set n=0
for /f "usebackq delims=" %%i in (`findstr /n .* %~f1`) do @set /a n+=1
@echo %~f1 :该文件行数为:%n%
pause
这里把空行也纳入了统计,把上面保存为linecount.bat文件,然后运行
linecount xxxx.txt
就能显示行数结果了。(别忘记用notepad++之类把bat文件存成ANSI格式,否则运行结果中文乱码!)
出处:https://zhidao.baidu.com/question/273864134.html
=======================================================================================
怎么利用批处理查看一个文件有多少行
@echooff
set/p"file=请输入文件名:"
for /f "delims=:" %%a in('findstr/n .* "%file%"') do set lineno=%%a
echo %file%有%lineno%行
出处:https://wenwen.sogou.com/z/q805194893.htm
=======================================================================================
bat批处理获取文件行数
在windows下用batch命令获取文件行数,我的思路是用FOR语句来循环读取,但是在实验的过程中有点慢,请问有没有更好的方法?我的代码如下:
@ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION SET lines=0 IF "%1" == "" ECHO No Input File! & EXIT /B FOR /F "tokens=* delims=" %%i IN (%1) DO ( SET /A lines=!lines!+1 ) ECHO 当前文件共 !lines! 行!
---------------------------------------------------------------------------------------
@echo off REM 针对本程序斑驳不担保任何责任,欲知详细请查看 GPL.txt REM 这是一个自由的程序,欢迎您在特定条件下再次发布本程序。 REM REM 再次感谢您使用本脚本 REM 斑驳敬上 REM set file_name=%1 if not defined file_name (goto bad) if not exist %1 (goto err) for /f "tokens=1 delims=][" %%i in ('find /n /v "" %1') do ( set line=%%i ) echo total line: %line% goto :eof :bad echo usage: %~n0 file_name goto :eof :err echo file: %1 not exist! goto :eof
---------------------------------------------------------------------------------------
感谢楼上,看了你的代码,我查了下findstr /?,其实直接用以下命令也是可行的
findstr /n /i /v /x "!!~~~~~~~~~~~~~~~!!~~" [filepath]
后续可以根据以上代码打印出来的东西进行筛选
出处:https://www.wenjiangs.com/group/topic-8947.html
标签:do,set,行数,批处理,delims,echo,%%,文本文件,REM From: https://www.cnblogs.com/mq0036/p/17119405.html