Hello, I would like to store content of .xml file inside .cmd file in :XML section. I'll place it's content (any lines) in .cmd manually. Later I would like to copy content of batch :XML section to other file. Is there any way to achieve this?
http://www.robvanderwoude.com/escapechars.php follow the escape sequence column. echo "your line" >> x:\yourfile.xml
If I understand correctly that sounds like a fairly trivial matter. Code: @Echo Off SetLocal Rem Finding line number of :XML label For /F "Delims=:" %%a In ('FindStr/N ^:XML$ "%~f0"') Do Set LN=%%a Rem Writing all lines below :XML label to another file More "%~f0" +%LN%>AnotherFile.xml GoTo :EOF Rem XML section to write to another file :XML <?xml version="1.0"?> <settings> <lister_plugin fontColor="0" bgColor="16777215" fontSize="10" fontFx="0" font="Courier New" /> <gui lang="" /> <debug logLevel="0" /> <path path_7z_dll="" path_7zG_exe="" /> <path64bit path_7zG_exe="" path_7z_dll="" /> <compression save="1" sfx="7z.sfx" updateSfx="0" askByContent="0" askByContentTimeout="1" alwaysWait7zip="0" extractToTempCount="20" deleteToRecycleBin="1" keySimpleMode="-1"> <settings_7zip Level="0" Archiver="" ShowPassword="0" EncryptHeaders="0"> <Options /> </settings_7zip> </compression> <passwords save="0" /> <formats save="1" /> <formatsDisabled /> </settings>
Thank you compo. Works fine if the :XML section is at the end of the batch. What if I want to do exactly the same with .vbs in the same batch file? How to do and where to add "stop reading here" for XML, continue the batch, "start reading here" for .vbs and stop again?
Just for fun, here's an example utilising a new method and the one I've already provided. Code: @Echo Off SetLocal EnableDelayedExpansion Rem Any code goes here... If Exist AnotherFile.xml GoTo XMLEnd Set "SN=" For /F "Skip=1 Delims=:" %%a In ('FindStr/N ^:XML "%~f0"') Do ( If Not Defined SN (Set "SN=%%a") Else (Set/A NC=%%a-SN-1)) <"%~F0" ( For /L %%a In (1,1,%SN%) Do Set/P = For /L %%a In (1,1,%NC%) Do (Set LN= Set/P LN= Echo(!LN!))>AnotherFile.xml GoTo XMLEnd :XMLBegin <?xml version="1.0"?> <settings> <lister_plugin fontColor="0" bgColor="16777215" fontSize="10" fontFx="0" font="Courier New" /> <gui lang="" /> <debug logLevel="0" /> <path path_7z_dll="" path_7zG_exe="" /> <path64bit path_7zG_exe="" path_7z_dll="" /> <compression save="1" sfx="7z.sfx" updateSfx="0" askByContent="0" askByContentTimeout="1" alwaysWait7zip="0" extractToTempCount="20" deleteToRecycleBin="1" keySimpleMode="-1"> <settings_7zip Level="0" Archiver="" ShowPassword="0" EncryptHeaders="0"> <Options /> </settings_7zip> </compression> <passwords save="0" /> <formats save="1" /> <formatsDisabled /> </settings> :XMLEnd Rem Rest of code goes here... Set "LN=" For /F "Delims=:" %%a In ('FindStr/N ^:VBSBegin$ "%~f0"') Do Set LN=%%a More "%~f0" +%LN%>AnotherFile.vbs GoTo :EOF :VBSBegin Set objFS = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("WScript.Shell") strCurrentDirectory = objShell.CurrentDirectory Set objFolder = objFS.GetFolder(strCurrentDirectory) Set colFiles = objFolder.Files Set objRE = New RegExp objRE.Global = True objRE.IgnoreCase = False objRE.Pattern = WScript.Arguments(0) For Each objFile In colFiles bMatch = objRE.Test(objFile.Name) If bMatch Then WScript.Echo objFile.Name End If Next If you can work it out, by all means use it but please note I will not be expanding upon it or answering questions on it.