【问题标题】:Batch file name and line counts in WindowsWindows 中的批处理文件名和行数
【发布时间】:2017-01-04 08:12:52
【问题描述】:

我正在使用以下命令写入目录中所有文件的文件名。

cmd /c dir /s /b /a:-d E:\SportsData /b /a:-d > E:\outputs\FileStats.txt

我还需要每个文件的行数。我怎样才能做到这一点?

【问题讨论】:

  • 您指定了两次dir 开关/ba:-d。你为什么在命令行前面加上cmd /c? “每个文件”是什么意思?

标签: windows file cmd


【解决方案1】:

在windows批处理中:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /R E:\SportsData %%f in (*) do (
    SET CurrentFile=%%f
    SET /a NumLines=0
    For /f %%j in ('Find "" /v /c ^< !CurrentFile!') Do Set /a NumLines=%%j
    ECHO !CurrentFile! has !NumLines! lines.
)
ENDLOCAL

【讨论】:

  • 谢谢!这会将文件名和计数写入屏幕
【解决方案2】:
    Set Inp = WScript.Stdin
    Set Outp = Wscript.Stdout
    Do Until Inp.AtEndOfStream
        Line=Inp.readline
        Count = Count +1
    Loop
    outp.writeline Count

使用

cscript //nologo c:\folder\vbsfile.vbs < inputfile

给出这个结果

C:\Windows\system32>cscript //nologo "C:\Users\User\Desktop\lc.vbs" < ..\win.ini
15

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 2012-12-10
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    相关资源
    最近更新 更多