Batch File arrays? - - An Overclocking Community

Forum Jump: 

Batch File arrays?

Thread Tools
post #1 of 3 (permalink) Old 07-31-2016, 10:06 PM - Thread Starter
New to
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:

@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
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

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

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

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]!

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

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

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  
Sponsored Links
post #2 of 3 (permalink) Old 08-01-2016, 01:32 AM
Join Date: Feb 2016
Posts: 2,668
You mention parsing variables to the batch file;

as in :
mybatch.bat helloworld
You can access the string "helloworld" with %1
Subsequent variables will be %2, %3 and so on.

You can find this info within 2 seconds on google.

The same goes for writing to a text file, super easy to find on google:
echo string you want in the text file>>textfile.txt
if you use a single ">" then you will overwrite the text file each time, ">>" will add another line each time.
For /f "delims=" %%m in (textfile.txt) do (
echo %%m
will go through each line of the text file.

I think if you made an effort you could find what you are looking for within one minute on google, would save you the time of posting a question here and waiting for someone to provide an answer. There is infinite resources on the web for batch programming.

Still struggling to see what the purpose of this script is and why you have chose batch for it, seems like the wrong thing to use (or at least seems like there would be a better solution to deal with websites n stuff). Are you sure the functionality you are looking for is not already included in a browser that you can download at the moment.
spinFX is offline  
post #3 of 3 (permalink) Old 08-02-2016, 12:49 PM - Thread Starter
New to
Wolfnuka's Avatar
Join Date: Jun 2011
Posts: 96
Rep: 2 (Unique: 2)
of course there are solution to this, i know that, bookmarks much? i just love the feeling of using the command prompt XD, and i do know how to use the commands you posted, my current code does all this and more, i can actually encrypt username and passwords using a batch script and save the data on a txt file and then decrypt and check the txt file database to be able to log in on a user account, etc, what i am trying to do is a little more complicated, as i said before

-i need to save variables, or plain text, to a text file << done
- i need to be able to find the plain text in the file, and use them as variables on the batch script so they can be used as a list:

i know i can make list using this syntax:
set /p choice="Enter your choice: "
if "%choice%"=="1" goto System Info

but what i am trying to do is to replace the items on the list, with text from a .txt file, get it? because the information (website address) will be added one by one manually, and i do not want to have a fixed list, like the code above, i want something dynamic, so i can change items as i wish from the batch program, and so far, i haven't been able to find a way where i can:

-find text on a text file and use it as a variable

i can find text on a file of course, but how to make it a variable?
Wolfnuka is offline  

Quick Reply

Register Now

In order to be able to post messages on the - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Please enter a password for your user account. Note that passwords are case-sensitive.
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off