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
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.
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.
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.
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^>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With