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

3

2

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?

Everyone

Posted 2011-07-17T15:08:00.440

Reputation: 1 714

Answers

6

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

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

surfasb

Posted 2011-07-17T15:08:00.440

Reputation: 21 453

Thanks mate! May I be so bold as to enquire how you acquired that little tid-bit? – Everyone – 2011-07-17T16:25:14.163

1

From the horse's mouth: http://technet.microsoft.com/en-us/library/bb490909.aspx. Generally, anything Product related is going to be under technet.microsoft.com. Anything programming related is going to be under msdn.microsoft.com (Microsoft Developer's network).

– surfasb – 2011-07-17T20:07:53.127