Wildcard to get files by exact extension

Viewed 2870

While diagnosing a larger batch script that needs to loop files with *.log extension I've found a funny behaviour. In a sample directory with files like this:

bar.log
foo.log
foo.log.ignore
foo.log.log-1676521099
not-related

... my little test script:

@echo off
setlocal enabledelayedexpansion
set DEF_LOG="C:\test\*.log"
for %%i in (%DEF_LOG%) do (
    echo %%i
)

... prints this:

C:\test\bar.log
C:\test\foo.log
C:\test\foo.log.log-1676521099

Digging deeper, I've found that's how Windows wildcards have been designed:

C:\>dir "C:\test\*.log" /b
bar.log
foo.log
foo.log.log-1676521099

My question is: how can I list all files that end exactly with .log?

3 Answers
Related