如果存在,则批量检查是否区分大小写

我需要检查给定的文件是否存在或不区分大小写,out.txt(全部是小写字母)文件存在于我运行脚本的位置。

码:

Case1: filename=out.txt if exist %filename% ( echo file exist... ) else echo File doesn't exist... Case2: filename=OUT.TXT if exist %filename% ( echo file exist... ) else echo File doesn't exist... 

对于这两种情况下,它显示文件存在…输出。 但我需要检查区分大小写。 它应该显示“File does not exist”msg for OUT.TXT

提前致谢

从参数中取文件名:

 @echo off dir %1 |find "%1" >nul if %errorlevel% == 0 (echo found) else (echo fail) 

dir实际上不区分大小写 – 但find是…

增加文件列表解析:

 @echo off for /f "delims=" %%z in ('type "namelist.txt" ') do ( if not exist "%%~z" echo "%%~z" not found if exist "%%~z" for %%a in ("%%~z") do if "%%a"=="%%~z" (echo "%%~z" is the right case) else (echo "%%~z" is the wrong case "%%a found") ) pause