Remove quotes in Forfiles output {cmd}

How do I remove the quotes from a variable in a cmd shell?

You need to use ~ parameter extension together with for /f to do this.

Use the following command:

for /f %i in ('FORFILES /S /M *.dmg /C "cmd /c if @fsize equ 1595694080 echo @fname"') do @echo %~i

To set a variable, and in a batch file, use the following command:

for /f %%i in ('FORFILES /S /M *.dmg /C "cmd /c if @fsize equ 1595694080 echo @fname"') do @set MyVariable=%%~i

Notes:

  • %~1 Expand %1 removing any surrounding quotes (")
  • In a batch file replace %i with %%i and %~i with %%~i

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • parameters - A command line argument (or parameter) is any value passed into a batch script.