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

15,799

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

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

Share:
15,799

Related videos on Youtube

Everyone
Author by

Everyone

I, am You.

Updated on September 18, 2022

Comments

  • Everyone
    Everyone over 1 year

    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
    Everyone almost 13 years
    Thanks mate! May I be so bold as to enquire how you acquired that little tid-bit?
  • surfasb
    surfasb almost 13 years
    From the horse's mouth: 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).