I am trying to get a file with a specific extension from a directory. To do that I am using the following batch file code:
for %%f in (.\*.ext) do (
echo %%f
)
This works fine, unless I have a file with .extsomething
extension.
I tried adding the $
wildcard to get only the exact matching, but it doesn't show any results with it.
for %%f in (.\*.ext$) do (
echo %%f
)
Since the *
wildcard is accepted, why the $
is not considered?
How can I get only the files with the exact extension?
Just add an if
statement:
@echo off
for %%f in (*.ext) do (
if "%%~xf"==".ext" echo %%f
)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments