Batch assign array value to variable - arrays

I have this code:
#echo off
SET /a counter=0
SET _inputname=
Set interfejs=ala
FOR /f "skip=3 tokens=*" %%a in ('netsh int ip show interfaces') do ( call :myfunct "%%a" )
SET /P _inputname=interface:
IF "%_inputname%" LEQ "%counter%" IF "%_inputname%" GTR "0" (
echo variable value:%_inputname%
call echo [%_inputname%] %%NetInterfNames[%_inputname%]%%
rem problem with assigning array value to a variable.
Set interfejs=%%NetInterfNames[%_inputname%]%%
echo to jest wybrany interface: %interfejs%
Rem split string
rem for /F "tokens=1,*" %%a in ("hello how are you") do echo %%b
)
IF "%_inputname%" GTR "%counter%" ( GOTO :EOF )
IF "%_inputname%" EQU "0" ( GOTO :EOF )
goto: EOF
:myfunct
set /a counter=%counter%+1
set NetInterfNames[%counter%]=%~1
call echo [%counter%] %%NetInterfNames[%counter%]%%
Inside I'm trying to assign a value taken from array to variable using this
Set interfejs=%%NetInterfNames[%_inputname%]%%
Problem is that value form array is not assigned.
Does anyone have an idea of what to do with it?

And here it is without enabling delayed expansion, to show you that you needed to use an additional Call, as per my commented advice. (I've added a Pause to allow you to see any output):
#Echo Off
Set "counter=0"
Set "_inputname="
Set "interfejs=ala"
For /F "Skip=3 Tokens=*" %%A In ('NetSh int ip show interfaces') Do Call :myfunct "%%A"
Set /P "_inputname=interface: "
If "%_inputname%" LEq "%counter%" If "%_inputname%" Gtr "0" (
Echo variable value:%_inputname%
Call Echo [%_inputname%] %%NetInterfNames[%_inputname%]%%
Rem no problem with assigning array value to a variable.
Call Set "interfejs=%%NetInterfNames[%_inputname%]%%"
Call Echo to jest wybrany interface: %%interfejs%%
Rem split string
Rem For /F "Tokens=1*" %%A In ("hello how are you") Do Echo %%B
)
If "%_inputname%" Gtr "%counter%" GoTo :EOF
If "%_inputname%" Equ "0" GoTo :EOF
Pause&GoTo :EOF
:myfunct
Set /A counter+=1
Set "NetInterfNames[%counter%]=%~1"
Call Echo [%counter%] %%NetInterfNames[%counter%]%%
However if you move two of your If commands, you can completely negate the need for one of the code blocks:
#Echo Off
Set "interfejs=ala"
Set "counter=0"
For /F "Skip=3 Tokens=*" %%A In ('NetSh int ip show interfaces') Do Call :myfunct "%%A"
Set "_inputname="
Set /P "_inputname=interface: "
If Not Defined _inputname GoTo :EOF
If "%_inputname%" Gtr "%counter%" GoTo :EOF
If "%_inputname%" Equ "0" GoTo :EOF
Echo variable value:%_inputname%
Call Echo [%_inputname%] %%NetInterfNames[%_inputname%]%%
Call Set "interfejs=%%NetInterfNames[%_inputname%]%%"
Echo to jest wybrany interface: %interfejs%
Rem split string
Rem For /F "Tokens=1*" %%A In ("hello how are you") Do Echo %%B
Pause&GoTo :EOF
:myfunct
Set /A counter+=1
Set "NetInterfNames[%counter%]=%~1"
Call Echo [%counter%] %%NetInterfNames[%counter%]%%
You could probably improve things a little too, still without enabling delayed expansion:
#Echo Off
For /F "Delims==" %%A In ('Set NetInterfNames[ 2^>NUL')Do Set "%%A="
For /F "Tokens=1* Delims=:" %%A In (
'NetSh int ip show interfaces 2^>NUL^|Findstr "[0-9]"^|FindStr /N "^"'
)Do Set "NetInterfNames[%%A]=%%B"&Call Echo [%%A] %%NetInterfNames[%%A]%%
:Input
Set /P "_inputname=interface: "
If Not Defined NetInterfNames[%_inputname%] GoTo Input
Call Set "_interfejs=%%NetInterfNames[%_inputname%]%%"
Echo to jest wybrany interface: %_interfejs%
Rem split string
Rem For /F "Tokens=1*" %%A In ("hello how are you") Do Echo %%B
Pause&GoTo :EOF
Or with delayed expansion:
#Echo Off
SetLocal EnableDelayedExpansion
For /F "Delims==" %%A In ('Set NetInterfNames[ 2^>NUL')Do Set "%%A="
For /F "Tokens=1* Delims=:" %%A In (
'NetSh int ip show interfaces 2^>NUL^|Findstr "[0-9]"^|FindStr /N "^"'
)Do Set "NetInterfNames[%%A]=%%B"&Echo [%%A] !NetInterfNames[%%A]!
:Input
Set /P "_inputname=interface: "
If Not Defined NetInterfNames[%_inputname%] GoTo Input
Set "_interfejs=!NetInterfNames[%_inputname%]!"
Echo to jest wybrany interface: %_interfejs%
Rem split string
Rem For /F "Tokens=1*" %%A In ("hello how are you") Do Echo %%B
Pause&GoTo :EOF

If you enabledelayedexpansion it will help you achieve this much easier.
#echo off
setlocal enabledelayedexpansion
SET /a counter=0
SET _inputname=
Set interfejs=ala
FOR /f "skip=3 tokens=*" %%a in ('netsh int ip show interfaces') do call :myfunct "%%~a"
SET /P _inputname=interface:
IF %_inputname% LEQ %counter% IF %_inputname% GTR 0 (
echo variable value:%_inputname%
echo [%_inputname%] !NetInterfNames[%_inputname%]!
Set interfejs=!NetInterfNames[%_inputname%]!
echo to jest wybrany interface: !interfejs!
)
IF %_inputname% GTR %counter% GOTO :EOF
IF %_inputname% EQU 0 GOTO :EOF
goto :eof
:myfunct
set /a counter+1
set NetInterfNames[%counter%]=%~1
call echo [%counter%] !NetInterfNames[%counter%]!

Related

Add numbers with same text together

I would like to create a batch file in which I can see what I have collected in a game.
The game saves this information in a .txt file.
The output would look like this.
70x Silver.
Back Pearl.
41x Copper.
Amethyst.
Amethyst.
12x Silver.
Back Pearl.
21x Copper.
5x Silver.
Back Pearl.
Back Pearl.
Amethyst.
What I want to do now, is to add the items with the same name together, like this:
128x Silver.
4x Back Pearl.
62x Copper.
3x Amethyst.
There are hundreds of items with different names, not just these 4.
Would that be possible?
Any help would be appreciated. Thanks!
Another one!
#echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%l in (test.txt) do for /F "tokens=1*" %%a in ("%%l") do (
set "first=%%a"
if "!first:~-1!" equ "x" (set /A "num=!first:~0,-1!") else set "num=0"
if !num! equ 0 (
set "rest=%%l"
set /A "count[!rest: =_!]+=1"
) else (
set "rest=%%b"
set /A "count[!rest: =_!]+=num"
)
)
(for /F "tokens=2* delims=[]=" %%a in ('set count[') do (
set "item=%%a"
if %%b equ 1 (
echo !item:_= !
) else (
echo %%bx !item:_= !
)
)) > summary.txt
#ECHO OFF
SETLOCAL
rem The following settings for the source directory and filename are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
SET "filename1=%sourcedir%\q72672485.txt"
:: remove variables starting #
FOR /F "delims==" %%b In ('set # 2^>Nul') DO SET "%%b="
FOR /f "usebackqdelims=" %%b IN ("%filename1%") DO (
CALL :sub %%b
)
SETLOCAL ENABLEDELAYEDEXPANSION
(
FOR /F "tokens=1,2delims==" %%b In ('set # 2^>Nul') DO (
SET "line=%%cx%%b"
ECHO !line:#= !
)
)>summary.txt
endlocal
type summary.txt
GOTO :EOF
:sub
SET "quantity=%1"
SET "line=%*"
IF /i "%quantity:~-1%"=="x" (SET /a quantity=%quantity:~0,-1%&SET "line=%line:* =%") ELSE SET quantity=1
IF %quantity%==0 SET /a quantity=1&SET "line=%*"
SET /a #%line: =#%+=quantity
GOTO :eof
Different approach...
Would that be possible? - Yes.
#echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in (t.txt) do (
set " z=%%a"
set " z=!z:x =#!"
set " z=!z: =_!"
for /f "tokens=1,2 delims=#" %%b in ("!z!") do (
if "%%c" == "" (
set "x=1"
set "y=%%b
) else (
set "x=%%b"
set "y=%%c"
)
set /a #!y!+=!x!
)
)
(for /f "tokens=1,2 delims=#=" %%a in ('set #') do (
set "x=%%a"
set "y=%%bx "
echo !y:~0,4! !x:_= !
))>summary.txt
Output with your example data (I hope, alphabetic sorting is ok for you):
3x Amethyst.
4x Back Pearl.
62x Copper.
87x Silver.
(your calculation of 120 silver might be a bit optimistic with the given input data)
This is a different approach that use a "file merge" method. The overall code is somewhat simpler than other methods...
#echo off
setlocal EnableDelayedExpansion
set "lineNum=0"
(for /F "tokens=1,2* delims=:x " %%a in ('(type test.txt ^& echo 0x^) ^| findstr /N "[0-9][0-9]*x"') do (
if !lineNum! lss %%a call :locateLine %%a
set "line=%%c"
set /A "count[!line: =_!]+=%%b"
)) < test.txt
set "count[="
(for /F "tokens=2* delims=[]=" %%a in ('set count[') do (
set "item=%%a"
if %%b equ 1 (echo !item:_= !) else echo %%bx !item:_= !
)) > summary.txt
goto :EOF
:locateLine num
set /A "lineNum+=1" & set /P "line=" & if errorlevel 1 exit /B
if %lineNum% lss %1 set /A "count[%line: =_%]+=1" & goto locateLine
exit /B
Another approach (splitting the file into items with and without quantity) (also fixing the Pollux Infusion issue in my first answer):
#echo off
setlocal enabledelayedexpansion
REM process lines without quantity:
for /f "delims=" %%a in ('type test.txt^|findstr /vrc:"[0123456789][0123456789]*x "') do call :count 1 "%%a"
REM process lines with quantity:
for /f "tokens=1*delims=x " %%a in ('type test.txt^|findstr /rc:"[0123456789][0123456789]*x "') do call :count %%a "%%b"
REM reformat:
(for /f "tokens=1,2 delims=#=" %%a in ('set #') do (
set "count=%%bx "
set "line=!count:~0,5!%%a" &REM including '1x'
if %%b==1 set "line= %%a" &REM supressing '1x'
echo !line:_= !
))>summary.txt
type summary.txt
goto :eof
:count
set item=%~2
set "item=%item: =_%"
set /a #%item% +=%1
Included both with and without 1x. Remove the line, you don't want.

how to remove a Negative using a txt editing batch script

I need a little help with this
I recently asked a different question on this same script
Now I have my scripted working for me and found a new issue
Here is my script
#ECHO Off
setlocal ENABLEDELAYEDEXPANSION
cd /d "%~dp0"
:: Significant part of string
set "params1="okhg": "
set "params2="tfed": "
set "params3="pkna": "
set "params4=txt": ""
#For %%G In ("%~dp0Preparing") Do Set "sourcedir=%%~fG"
#For %%G In ("%~dp0Ready") Do Set "destdir=%%~fG"
FOR /f "delims=" %%q IN ('dir /b /s /a-d "%sourcedir%\(*)*.txt"') DO (
rem calculate new destination directory
SET "newdest=%%~dpq"
SET "newdest=!newdest:%sourcedir%=%destdir%!"
SET "newdest=!newdest:~0,-1!"
MD "!newdest!" 2>nul
(
FOR /f "tokens=1 delims=()" %%j IN ("%%~nxq") DO (
rem %%j now has sequence number
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" "%%q"') do (
set "line=%%b"
for %%x in (%params1%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs1 %%j
for %%x in (%params2%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs2 %%j
for %%x in (%params3%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs3 %%j
for %%x in (%params4%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs4 %%j
echo(!line!
)
)
)>"!newdest!\%%~nxq"
)
GOTO :eof
:: substitute
:subs1
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params1%%%s=%params1%!"
IF "%original%" neq "%line%" goto subs1
set "line=!line:%params1%=%params1%%1!"
GOTO :eof
:subs2
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params2%%%s=%params2%!"
IF "%original%" neq "%line%" goto subs2
set "line=!line:%params2%=%params2%%1!"
GOTO :eof
:subs3
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params3%%%s=%params3%!"
IF "%original%" neq "%line%" goto subs3
set "line=!line:%params3%=%params3%%1!"
GOTO :eof
:subs4
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params4%%%s=%params4%!"
IF "%original%" neq "%line%" goto subs3
set "line=!line:%params4%=%params4%CITY%1!"
GOTO :eof
This is how it works
ORIGNAL FOLDER
+ ----- FOLDER 1
--------+ --(100) Filename.txt
-------------+ -- "okhg": 452587"
-------------+ -- "tfed": 6541"
-------------+ -- "pkna": -58452"
-------------+ -- "txt": ""
RESULTS FOLDER
+ ----- FOLDER 1
--------+ --(100) Filename.txt
-------------+ -- "okhg": 100"
-------------+ -- "tfed": 100"
-------------+ -- "pkna": 100-58452"
-------------+ -- "txt": "CITY100"
The issue I am coming across with is that this line has a negative
"pkna": -58452"
I have tested different ways to make the scripts remove the negative
if I leave it like this, I get this result
set "params3="pkna": "
"pkna": 100-58452"
if I do this, I get this result
set "params3="pkna": -"
"pkna": -100"
what I am looking for is this
"pkna": 100"
Thank you
Edit:
The question has been updated with an answer.
The code will "code" multiple row/lines in to a text file using its prefix name, or with a "more direct" coding.
If you do know a way to clean up the code feel free to post an answer to do so., I would like to leave a script that I can continue to add more codes if needed
Thank you for all the hard work you'll provide us with to make our scripts better
#ECHO Off
setlocal ENABLEDELAYEDEXPANSION
cd /d "%~dp0"
:: Significant part of string
set "params1="okhg": "
set "params2="tfed": "
set "params3="pkna": "
set "params4=txt": ""
#For %%G In ("%~dp0Preparing") Do Set "sourcedir=%%~fG"
#For %%G In ("%~dp0Ready") Do Set "destdir=%%~fG"
FOR /f "delims=" %%q IN ('dir /b /s /a-d "%sourcedir%\(*)*.txt"') DO (
rem calculate new destination directory
SET "newdest=%%~dpq"
SET "newdest=!newdest:%sourcedir%=%destdir%!"
SET "newdest=!newdest:~0,-1!"
MD "!newdest!" 2>nul
(
rem this will take the data in the filename enclosed in (!)
FOR /f "tokens=1 delims=()" %%j IN ("%%~nxq") DO (
rem this will replace any random codes found after : with 10
FOR /f "tokens=1 delims=()" %%k IN ("10") DO (
rem this will add any wording after this : and will take data enclosed in (!)
FOR /f "tokens=1 delims=()" %%l IN ("%%~nxq") DO (
rem %%j %%k %%l now has sequence number or pattern
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" "%%q"') do (
set "line=%%b"
rem in order to make each code work I gave them there own ::Substitute
for %%x in (%params1%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs1 %%j
for %%x in (%params2%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs2 %%j
for %%x in (%params3%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs3 %%k
for %%x in (%params4%) do if defined line IF "%%b" neq "!line:%%x=!" CALL :subs4 %%l
echo(!line!
)
)
)
)
)>"!newdest!\%%~nxq"
)
GOTO :eof
:: substitute
:subs1
SET "line=%line:-=%"
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params1%%%s=%params1%!"
IF "%original%" neq "%line%" goto subs1
set "line=!line:%params1%=%params1%%1!"
GOTO :eof
:subs2
SET "line=%line:-=%"
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params2%%%s=%params2%!"
IF "%original%" neq "%line%" goto subs2
set "line=!line:%params2%=%params2%%1!"
GOTO :eof
:subs3
SET "line=%line:-=%"
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params3%%%s=%params3%!"
IF "%original%" neq "%line%" goto subs3
set "line=!line:%params3%=%params3%%1!"
GOTO :eof
:subs4
SET "line=%line:-=%"
SET "original=%line%"
FOR /L %%s IN (0,1,9) DO set "line=!line:%params4%%%s=%params4%!"
IF "%original%" neq "%line%" goto subs3
set "line=!line:%params4%=%params4%City%1!"
GOTO :eof

Batch IF command not running

I'm trying to grab a couple of lines in some files and store them in variables (line3 and line4).
Here is the code:
setlocal EnableDelayedExpansion
for /f "tokens=*" %%a in ('dir *.md /b /o:-n /a:-d') do (
call :getLines "%%a"
)
pause
exit
:getLines
set /A cnt=2
for /f "skip=4 tokens=*" %%b in (%1) do (
set /A cnt+=1
set "line!cnt!=%%b"
if !cnt! == 4 (
set "filename=%~n1"
set "blogdate=!filename:~0,10!"
set "blogtitle=!filename:~11!"
echo hello
echo !line3!
echo !line4!
echo !filename!
echo !blogdate!
echo !blogtitle!
)
)
goto :eof
The above will not even echo hello. I can't see what's wrong.
This is what each file looks like:
# Title
*2015-11-17*
Tags: word1 word2
First Sentence is here.
Filenames look like this:
2015-11-17-title.md
You passed to call with quotes, so you should strip it first (or use usebackq).
Also when you are testing, don't use exit yet.
Try this, see if it works:
(Formatted so the structure is more clear, try comment #echo off to get more details.)
#echo off
setlocal EnableDelayedExpansion
for /f "tokens=*" %%a in ('dir *.md /b /o:-n /a:-d') do (
call :getLines "%%a"
)
pause
::exit
goto :eof
:getLines
set /A cnt=2
for /f "usebackq skip=4 tokens=*" %%b in (%1) do (
set /A cnt+=1
set "line!cnt!=%%b"
if !cnt! == 4 (
set "filename=%~n1"
set "blogdate=!filename:~0,10!"
set "blogtitle=!filename:~11!"
echo hello
echo !line3!
echo !line4!
echo !filename!
echo !blogdate!
echo !blogtitle!
goto :eof
)
)
goto :eof
for will take the input with quotes as string not as file.
%~1 will strip %1's quotes.
Check for /? and call /? for more details.

Batch Loop in loop

trying to get a batch to output network adapter names for another batch file. so far this works...
#echo off
set ignore=true
for /F "delims=" %%a in ('netsh interface show interface')do call :Sub %%a
goto :eof
:sub
if not "%adapter1%" EQU "" goto :2
set Line=%*
if "%Line:~0,10%" EQU "----------" (set ignore=false & goto :eof)
if %ignore% EQU true goto :eof
for /F "tokens=4*" %%b in ('echo %*') do set Adapter1=%%b
echo %Adapter1%
goto :eof
)
:2
for /F "tokens=4*" %%c in ('echo %*') do set Adapter2=%%c
echo %adapter2%
pause
But is there a way to loop the second part so the output would continue with
Adapter#="Adapter Name" until there are no adapters left.
I've tried to use..
set /a c=1
:sub
for /F "tokens=4*" %%c in ('echo %*') do (
set /a c=c+1
Set Adapter%c%=%%b
echo %adapter2%
)
couple of issues here trying to call a variable made of Variables ie.%adapter%c%%
and the other being i have no idea how to loop this back to the next line.
I realise i could keep expanding this but it would be horrendous.
#echo off
set ignore=true
for /F "delims=" %%a in ('netsh interface show interface')do call :Sub %%a
goto :eof
:sub
if not "%adapter2%" EQU "" goto :3
if not "%adapter1%" EQU "" goto :2
set Line=%*
if "%Line:~0,10%" EQU "----------" (set ignore=false & goto :eof)
if %ignore% EQU true goto :eof
for /F "tokens=4*" %%b in ('echo %*') do set Adapter1=%%b
echo %Adapter1%
goto :eof
)
:2
for /F "tokens=4*" %%c in ('echo %*') do set Adapter2=%%c
echo %adapter2%
pause
:3
for /F "tokens=4*" %%c in ('echo %*') do set Adapter3=%%c
echo %adapter3%
pause
Frustrated >.< , can't get my head around how its supposed to work. Any help appreciated. Thanks
It's much easier to skip the first 3 lines of the output
As the adapter name could contain spaces your approach with tokens=4 can't work,
use an asterisk to catch the remainder of the parsed line in the next for var.
:: Q:\Test\2019\03\15\SO_55189424.cmd
#Echo off&SetLocal EnableDelayedExpansion
Set Cnt=0
for /f "skip=3 tokens=1-3*" %%A in ('
netsh interface show interface
') Do (
Set /A Cnt+=1
Set "Adapter!Cnt!=%%D"
)
Set Adapter
Sample Output:
> Q:\Test\2019\03\15\SO_55189424.cmd
Adapter1=VirtualBox Host-Only Network
Adapter2=Ethernet
Adapter3=Ethernet 2

Kelogger/pasowrd asterrix replace

I would like to make a keylogger and I want the password to look like its asterisk like in the log on:
#echo off
mode con: cols=10000 lines=300
color a
title Login
cls
echo LOGIN ERROR
ver
echo (c) 2017 Microsoft Corporation. All rights reserved.
echo.
cd “C:Logs”
set /p user=Username:
set /p pass=Password:
echo Username=”%user%” Password=”%pass%” >> Log.txt
start open2.bat
exit
I expect it to look real I have tried searching but all I found is for the log on screen I want it for the desktop
just text no asterisks
I know this is a duplicate question here on StackOverFlow but I can't find it. I may have found this code on DosTips.com as well. When I find the original links I will update the question.
Essentially this is the code you are looking for to mask password input with asterisks.
#echo off &setlocal
:username
cls
SET "username="
SET /P "username=Enter your username:"
IF NOT DEFINED username GOTO username
:password
cls
<nul set /p "=Enter your password: "
call :HInput password
IF NOT DEFINED password GOTO password
setlocal EnableDelayedExpansion
echo user:%username% pass:!password!
pause
goto :eof
:HInput [ByRef_VarName]
:: inspired by Carlos
:: improved by pieh-ejdsch
if "%__HI__%" neq "__HI__" (
setlocal DisableDelayedExpansion
set "S=" &set "N=0" &set "__HI__=__HI__"
for /f %%i in ('"prompt;$h&for %%i in (1) do rem"') do set "BS=%%i"
)
set "C="
for /f "eol=1 delims=" %%i in ('xcopy /lwq "%~f0" :\') do set "C=%%i"
set "C=%C:~-1%"
setlocal EnableDelayedExpansion
if not defined C (
echo(
if "%~1"=="" (
echo(!S!
endlocal &endlocal &exit /b %N%
) else (
if defined S (
for /f delims^=^ eol^= %%i in ("!S!") do endlocal &endlocal &set "%~1=%%i" &exit /b %N%
) else endlocal &endlocal &set "%~1=" &exit /b 0
)
)
if "!BS!"=="!C!" (
set "C="
if defined S set /a "N -= 1" &set "S=!S:~,-1!" &<nul set /p "=%BS% %BS%"
) else set /a "N += 1" &<nul set /p "=*"
if not defined S (
endlocal &set "N=%N%" &set "S=%C%"
) else for /f delims^=^ eol^= %%i in ("!S!") do endlocal &set "N=%N%" &set "S=%%i%C%"
goto HInput

Resources