1

我需要检查给定文件是否存在,区分大小写,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 的“文件不存在”消息

提前致谢

4

2 回答 2

2

从参数中获取文件名:

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

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

于 2013-06-24T11:21:07.117 回答
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
于 2013-06-24T10:01:49.877 回答