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

问题描述 投票:1回答:2

我需要检查给定文件是否存在,区分大小写,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...

对于这两种情况,它显示文件存在...输出。但我需要检查区分大小写。它应该显示OUT.TXT的“文件不存在”消息

提前致谢

windows batch-file
2个回答
2
投票

从参数中取出文件名:

@echo off 
dir /b /a-d "%~1"|find "%~1" >nul
if %errorlevel% == 0 (echo found) else (echo fail)

diris实际上不区分大小写 - 但find是......


1
投票

添加了文件列表解析:

@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
© www.soinside.com 2019 - 2024. All rights reserved.