findstr: How to escape the dot?
How can I escape the wildcard .
in order to match a literal .
character?
You are on the right lines with using a \
, however you need an additional .
in order to find the remaining characters.
findstr /ie "_s\..*"
Example (type and a cmd
shell):
F:\test>dir /b /a:-d | findstr /ile "gif jpg png svg" | findstr /ie "_s.*"
aaa_s.jpg
bbb_s.jpg
ccc_s.jpg
aaa_small.jpg
bbb_small.jpg
ccc_small.jpg
F:\test>dir /b /a:-d | findstr /ile "gif jpg png svg" | findstr /ie "_s\..*"
aaa_s.jpg
bbb_s.jpg
ccc_s.jpg
So your batch file should contain:
for /f "delims=" %f in ('dir /b /a:-d ^| findstr /ile "gif jpg png svg" ^| findstr /ie "_s\..*"') do echo "%f"
For this specific task you can also escape the "."
in the findstr
by not using it if you replace:
dir /b /a:-d
→ where .:*_s.*
findstr /ie "_s\.*"
→ findstr /ei "gif jpg png svg"
where .:*_s.*|findstr /ei "gif jpg png svg"
for /f delims^= %f in ('where .:*_s.*^|findstr /ei "gif jpg png svg"')do echo "%~nxf"