Windows – How to extract the filename extension out of %f in script

consolefile extensionfilenamesscriptwindows

The windows %%f returns the full name of the file as 'filename.ext'

e.g.

for /r %%f in (*.wav) do echo %%f

Is there a way to extract the filename without the extension from %%f?

Best Answer

Change echo %%f to echo %%~nf.

~n tells the cmd to expand f to equal only the filename, minus the extension.