I assume you want to know whether the given item is an existing file but not a directory (note that directories can also have an extension). Use a trailing \
to distinguish between file and directory:
if exist "file.ext" (
if exist "file.ext\" (
echo The given item is a directory.
) else (
echo The given item is a file.
)
) else (
echo The given item does not exist.
)
Or in short:
if exist "file.ext" if not exist "file.ext\" echo This is a file but not a directory.
If you really want to check the name of a given item whether or not there is an extension, you could use a for
loop:
for %%I in ("file.ext") do (
if not "%%~xI"=="" (
echo The given item has got the extension "%%~xI".
)
)