change if %%a
to if /i %%a
which makes the string-match case-insensitive.
BTW, set /a typefile=!typefile!+1
could just as easily be set /a typefile+=1
문제
i check the extension of a file (.iso or .img):
set extension=%~x1
set typefile=0
FOR %%a IN (.iso .img) DO (
if %%a==%extension% set /a typefile=!typefile!+1
)
if %typefile%==0 (
GOTO NOMOUNT
) else (
GOTO MOUNT
)
its works, but the problem is when the file have a filename like this for example:
9600.16384.130821-1623_x64fre_Client_IT-IT-IRM_CCSA_DV5.ISO
in this case the %typefile%
is set=0
also if the file is an iso.
해결책
change if %%a
to if /i %%a
which makes the string-match case-insensitive.
BTW, set /a typefile=!typefile!+1
could just as easily be set /a typefile+=1
다른 팁
Your immediate problem is NOT related to long filenames, but to case-sensitivity when comparing strings - see @Magoo's answer.
However, overall it's not entirely clear what you're trying to achieve; for instance, your for
loop enumerates string literals - .iso
and .img
- rather than trying to match filenames in the current folder with patterns *.iso
and *.img
.
The following solution assumes that you want to count all files in the current folder whose filename extension case-insensitively matches the extension passed in as the 1st argument (including the initial .
):
REM The extension to match; specify _with_ initial `.`, e.g. `.iso`
REM `~x` ensures that if a whole filename was specified, only the extension
REM is extracted.
set extension=%~x1
set typefile=0
FOR %%a IN (*%extension%) DO (
set /a typefile+=1
)
if %typefile% EQU 0 (
GOTO NOMOUNT
) else (
GOTO MOUNT
)
Note:
*.iso
always performs case-INsensitive matching; e.g., *.iso
will match both files named f1.iso
and f2.ISO
.EQU
is better than ==
.set /a
inside a for
loop works even if setlocal enabledelayedexpansion
is NOT in effect.