There is a parameter passed in cmd in the format "ARG=CUSTOM_SOURCE,SOURCE=C:\Folder\OtherFolder\SourceFiles" . In order to highlight ARG and SOURCE with their values, you must convert the parameter to the format ARG=CUSTOM_SOURCE,SOURCE=C:\Folder\OtherFolder\SourceFiles

Code:

 set test=%1 for /f "delims=" %%A in ("!test!") do set "test=%%~A" echo test after process is "%test%" rem output: ""ARG=CUSTOM_SOURCE,SOURCE=C:\Folder\OtherFolder\SourceFiles"" :nextVar for /F "tokens=1* delims=," %%a in ("%test%") do ( set %%a set test=%%b ) if defined test goto nextVar set test=%ARG% 

Also tried this option:

 set test=%test:"=% 

The result is the same: ""ARG=CUSTOM_SOURCE,SOURCE=C:\Folder\OtherFolder\SourceFiles""

Where is the mistake? How to remove quotes?

    2 answers 2

    If the position of the characters to be deleted (in this case, double quotes) has a certain order - at the beginning and at the end. Can it not bother, but just delete them? Here is an example for trimming a string from the edges one character at a time.

     @set test="ARG=CUSTOM_SOURCE,SOURCE=C:\Folder\OtherFolder\SourceFiles" @set test=%test:~1,-1% @echo.%test% 

    If the position of the quotation marks is not defined, then you need to do what you suggested - by processing the string. But there is a nuance, for processing you need to turn on the mode of processing variables through a symbol! And then turn it off. From here we have the following code.

     @set test="ARG=CUSTOM_"""SOURCE,SOURCE=C":\Fo""lder\OtherFolder\SourceFiles" @setlocal EnableDelayedExpansion @set test=!test:"=! @setlocal DisableDelayedExpansion @echo %test% 
    • There may be parameters without quotes, they will not work. It is necessary to remove the quotes. - user5554178
    • Completed the answer. - Daemon-5
    • I have the setlocal EnableDelayedExpansion line at the beginning of the code, as I understood, it still did not help. - user5554178
    • So you yourself wrote that you used the variable "% test%" , but you should have "! Test!" - Daemon-5
    • one
      setlocal EnableDelayedExpansion was used to avoid escaping / dividing the string with quotes when setting the variable with the set command. That is what I meant in my answer. - Daemon-5

    It turned out to remove quotes in this way:

     set test=%1 :nextVar for /F "tokens=1* delims=," %%a in ("%test:"=%") do ( set %%a set test=%%b ) if defined test goto nextVar set test=%ARG% 

    It still remains unclear why set test=%test:"=% did not give the same result