Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove quote from forfiles variables

I need to generate an xml from windows command prompt using the forfiles command.

I'm not so far, but the variable contains quotes and i don't want it ...

Here my current command:

%FF_CMD% /c "cmd /c if @isdir==TRUE echo ^<root^>^<dir^>@fname^</dir^>^</root^>"

the result is:

<root><dir>"DIRNAME"</dir></root>

but i want this:

<root><dir>DIRNAME</dir></root>

any idea ?

thanks in advance

like image 261
fedevo Avatar asked Mar 20 '12 12:03

fedevo


People also ask

How to remove quotes in Batch?

Double quotes can be removed from variables in a Batch file using the tilde ( ~ ) character. The tilde ( ~ ) character is used in many ways in Batch files. Apart from being an argument quote removal, it is also used to extract a substring from a string variable in a Batch file.

How do you remove quotes from a string?

Use the String. replaceAll() method to remove all double quotes from a string, e.g. str. replaceAll('"', '') . The replace() method will return a new string with all double quotes removed.

What does the forfiles command do?

The forfiles command lets you run a command on or pass arguments to multiple files. For example, you could run the type command on all files in a tree with the . txt file name extension.


1 Answers

You can create additional batch file, say "echoxml.bat". This will allow to use ~ notation to strip quotes:

@echo off
echo ^<root^>^<dir^>%~1^</dir^>^</root^>

and then use the batch file in forfiles:

%FF_CMD% /c "cmd /c if @isdir==TRUE echoxml.bat @fname"

EDIT: Another option would be to change forfiles to for, or even for /d if it is possible (I do not know what arguments you use in %FF_CMD%):

@echo off
for /d %%A in (*) do echo ^<root^>^<dir^>%%~A^</dir^>^</root^>
like image 61
MBu Avatar answered Oct 05 '22 00:10

MBu