禁止“找不到文件"在批处理文件中 [英] Suppress "File Not Found" in Batch File

查看:194
本文介绍了禁止“找不到文件"在批处理文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在bat文件下运行,这给了我一个文件夹中存在的文件数,我正在按文件数进行计数,但是如果没有文件,我会得到找不到文件"

I was trying to run below bat file which gives me number of files present in a folder, i was getting the count as per the files but if there is no files i am getting "File Not Found"

计数为0,这是可以的,但我要禁止显示找不到文件"

Count is 0 and which is okay, but i want to suppress "File Not Found"

脚本:

@echo off

setlocal enabledelayedexpansion

@echo off

set c2=0

echo Folder,NoOfFiles

for  /f "tokens=*" %%x in ('dir /s /a /b "D:\Flow\Flow1\Flow2\Flow3\NGR*.txt"') do set /a c2+=1

echo.NGR,!c2!

结果:

文件夹,NoOfFiles

Folder,NoOfFiles

找不到文件

NGR,0

按任意键继续. .

我试图使用2> nul,但那也没有用

I was trying to use 2>nul but that was also not working

有人可以帮助我获得解决方案吗,在这里可以做什么?

Can someone please help me to get the solution, what can be done here?

推荐答案

尝试使用:

for  /f "tokens=*" %%x in ('dir /s /a /b "D:\Flow\Flow1\Flow2\Flow3\NGR*.txt" 2^>nul') do set /a c2+=1

这篇关于禁止“找不到文件"在批处理文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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