Suppress “File Not Found” in Batch File

£可爱£侵袭症+ 提交于 2019-12-11 07:27:28

问题


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"

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

Script:

@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!

Result:

Folder,NoOfFiles

File Not Found

NGR,0

Press any key to continue . . .

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?


回答1:


try with :

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


来源:https://stackoverflow.com/questions/46955101/suppress-file-not-found-in-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!