How to remove quotation from forfiles variables

I need to create an xml command line from the command line using the forfiles command.

I'm not that far, but the variable contains quotation marks, and I don't want this ...

Here is my current command:

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

result:

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

but I want this:

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

any idea?

early

+4
source share
1 answer

You can create an additional batch file, for example, "echoxml.bat". This will allow the use of the ~ notation to highlight quotes:

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

and then use the batch file in the files:

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

EDIT: Another option is to change the forfiles to for or even for /d , if possible (I don't know what arguments you use in %FF_CMD% ):

 @echo off for /d %%A in (*) do echo ^<root^>^<dir^>%%~A^</dir^>^</root^> 
+5
source

Source: https://habr.com/ru/post/1402422/


All Articles