5

So I am running this command:

FORFILES /S /M *.dmg /C "cmd /c if @fsize equ 1595694080 echo @fname"

and the output:

"058-26174-078"

but the problem is that I want the name without the quotations

like this: 058-26174-078

3

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

0
0

Use the for command, here is an example:

@echo off
FORFILES /S /M *.dmg /C "cmd /c if @fsize equ 1595694080 set quote=@fname"
for %%a in (%quote%) do set dequote=%%~a

And you can use the %dequote% variable to get the dequoted string, I may have got the syntax wrong because I have never worked with the forfiles command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.