1

I need to check whether the given file is exist or not with case sensitive, out.txt(all are small letters) file is present in location where i running the script.

Code:

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...

For both case it showing file exist... output. But i need to check with case sensitive. It should show "File doesn't exist" msg for OUT.TXT

Thanks in advance

user1553605
  • 1,333
  • 5
  • 24
  • 42

2 Answers2

2

take filename from parameter:

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

diris in fact not case sensitive - but find is...

Stephan
  • 53,940
  • 10
  • 58
  • 91
1

Added file list parsing:

@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
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • Thanks... but here the script getting file names from another script as input.. we don't know the file name here to compare like "OUT.TXT". If we compare like, for %%a in (%filename%) do if "%%a"=="%filename%" echo file exists... the result is same like "if exist %filename%" – user1553605 Jun 24 '13 at 10:15
  • @user1553605 If you wanted to parse a list of filenames then say so. My code did what you asked. See the change above for file parsing. – foxidrive Jun 24 '13 at 10:28