Overclock.net - An Overclocking Community - View Single Post - Batch File arrays?

View Single Post
post #1 of (permalink) Old 07-31-2016, 10:06 PM - Thread Starter
Wolfnuka
New to Overclock.net
 
Wolfnuka's Avatar
 
Join Date: Jun 2011
Posts: 96
Rep: 2 (Unique: 2)
Hi guys, so i'm learning some batch, i know, arcane, but still i think it is relatively easy to learn and useful for some stuff, i know a bit of C, but that's about it, case in point, i am trying to make a website list logger, basically a batch file that:

- asks you to enter a website address, then saves it to a text file
- when you reopen the website logger batch file, it can pull the info from the text file to display the website lists as obviously, a list
- be able to choose from the list a website to open it

is pretty straight forward so i thought about arrays, but apparently is harder than it looks, so far, i got this examples from the guys at stackoverflow:


Code:
@echo off
setlocal enabledelayedexpansion
Set "StartIndex=0"
Set "EndIndex=3"
Rem To populate the array
for /L %%i in (%StartIndex%,1,%EndIndex%) do (
    echo Write something 
    set /p "Array[%%i]="
)
echo Enter any key to show the values of the elements in the array
pause>nul
Rem To show the values of the elements in the array
For /L %%i in (%StartIndex%,1,%EndIndex%) do (
    echo Array[%%i] = !Array[%%i]!
)
echo Write anything to add and store it as new element 4 in the array
pause>nul 

Set /P "Array[4]="
echo Array[4] = !Array[4]!
echo Write anything to add and store it as new element 5 in the array 
pause>nul

Set /P "Array[5]="
echo Array[5] = !Array[5]! 
echo Hit any key to show the new array with values added
pause>nul

for /L %%i in (0,1,5) do (
    echo Array[%%i] = !Array[%%i]!
)

Rem Modification of an element
echo Write something here to replace Array[3] = !Array[3]!
pause>nul

set /p "Array[3]="
echo The new element is updated as Array[3] = !Array[3]!

echo Hit any key to show the modification
pause>nul
for /L %%i in (0,1,5) do (
    echo Array[%%i] = !Array[%%i]!
)
pause

i know how i can modify this example to make it work to make the list, but it still doesn't solve the problem of being able to SAVE the website list to a text file and later on reopen the batch and list the SAVED websites on the batch program, i know how to copy variables to a text file and then READ it back to the batch program, but i can't find a way to:

-save variable to a text file and read it back and use it as a variable on the batch program,

any ideas on how this can be accomplish? any help is appreciated
Wolfnuka is offline