I did a small array manipulation function
Works great but I'd like to improve it some more.
Here is the demo code
Code: Select all
:MoveObject-DEMO
set myarray[0]=Open Source, light and extremely simple,
set myarray[1]=It is a single executable file with no dependencies.
set myarray[2]=Just download it and add it to your PATH
set myarray[6]=Create, edit, copy, move, download your files easily,
set myarray[7]=everywhere, every time. Use it as your personal cloud.
set myarray.ubound=7
echo.&echo Printing myarray&echo.
call :echoarray myarray LINENUMBERS
echo.&echo Moving object [6] to [4]&echo.
call :moveobject myarray[6] myarray[4]
echo.&echo Printing myarray&echo.
call :echoarray myarray LINENUMBERS
echo.&echo Moving object [4] to [3]&echo.
call :moveobject myarray[4] myarray[3]
echo.&echo Printing myarray&echo.
call :echoarray myarray LINENUMBERS
echo.&echo Moving objects [1][2][3] to [4][5][6]&echo.
call :moveobject myarray[1] myarray[4]
call :moveobject myarray[2] myarray[5]
call :moveobject myarray[3] myarray[6]
echo.&echo Printing myarray&echo.
call :echoarray myarray LINENUMBERS
GoTo :EOF
:MoveObject
for /f "tokens=1,2* delims==" %%a in ('set %~1 2^>nul') do if "[%%a]" EQU "[%~1]" set %~2=%%b
for /f "tokens=1 delims==" %%a in ('set %~1. 2^>nul') do for /f "tokens=2 eol== delims=.=" %%b in ('set %%a 2^>nul') do for /f "tokens=2* delims==" %%c in ('set %%a 2^>nul') do set %~2.%%b=%%c
if "[%~1]" NEQ "[]" for /f "tokens=1,2 delims==" %%a in ('set %~1 2^>nul') do set %%a=
GoTo :EOF
Also related function DeleteObject
eleteObject
if "[%~1]" NEQ "[]" for /f "tokens=1,2 delims==" %%a in ('set %~1 2^>nul') do set %%a=
if "[%~2]" NEQ "[]" shift & GoTo eleteObject
GoTo :EOF
eleteObjectOnly
if "[%~1]" NEQ "[]" for /f "tokens=1,2 delims==" %%a in ('set %~1. 2^>nul') do set %%a=
if "[%~2]" NEQ "[]" shift & GoTo eleteObjectOnly
GoTo :EOF
Still need to add the DeleteArrayElement MoveArrayElement aliases to move only the element and not the object
Also to allow multiple object moves in one function call to MoveObject
Here is the output of the demo code
Code: Select all
MoveObject-DEMO.bat
Printing myarray
0:Open Source, light and extremely simple,
1:It is a single executable file with no dependencies.
2:Just download it and add it to your PATH
3:
4:
5:
6:Create, edit, copy, move, download your files easily,
7:everywhere, every time. Use it as your personal cloud.
Moving object [6] to [4]
Printing myarray
0:Open Source, light and extremely simple,
1:It is a single executable file with no dependencies.
2:Just download it and add it to your PATH
3:
4:Create, edit, copy, move, download your files easily,
5:
6:
7:everywhere, every time. Use it as your personal cloud.
Moving object [4] to [3]
Printing myarray
0:Open Source, light and extremely simple,
1:It is a single executable file with no dependencies.
2:Just download it and add it to your PATH
3:Create, edit, copy, move, download your files easily,
4:
5:
6:
7:everywhere, every time. Use it as your personal cloud.
Moving objects [1][2][3] to [4][5][6]
Printing myarray
0:Open Source, light and extremely simple,
1:
2:
3:
4:It is a single executable file with no dependencies.
5:Just download it and add it to your PATH
6:Create, edit, copy, move, download your files easily,
7:everywhere, every time. Use it as your personal cloud.
And I will attach the full test file