批处理代码不适用于文件名中的空间 [英] Batch code not working for space in the file name

查看:52
本文介绍了批处理代码不适用于文件名中的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试自动使用批处理文件,它将在Output.txt文件中显示文件名和文件中的记录数.但是,如果我的文件名中有空格,则不会给出记录数,而是显示以下文本空间

Trying to automate using batch file wherein it will display filename and number of records in the file in an Output.txt file.But if my filename has space, then it does not give number of records, instead it show the text following the space

@echo off


(
for %%n IN (*.*) do ( 
  for /F "tokens=3" %%f in ('find /V /C "-------------" "%%n"') do (

   echo %%n : %%f
  ) 
))  >output.txt

推荐答案

只需使用 tokens = 2,* ,忽略token2. * 的意思是将其余所有内容都删除,而无需再进行标记化"

just use tokens=2,*, ignore token2. * means "take all the rest without tokenizing any more"

@echo off
(
  for %%n IN (*.*) do ( 
    for /F "tokens=2 delims=:" %%f in ('find /V /C "-------------" "%%n"') do (
      echo %%n :%%f
    )
  )
)  >output.txt

这篇关于批处理代码不适用于文件名中的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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