Overclock.net - An Overclocking Community

Overclock.net - An Overclocking Community (https://www.overclock.net/forum/)
-   Coding and Programming (https://www.overclock.net/forum/142-coding-programming/)
-   -   Batch File arrays? (https://www.overclock.net/forum/142-coding-programming/1607464-batch-file-arrays.html)

Wolfnuka 07-31-2016 10:06 PM

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

spinFX 08-01-2016 01:32 AM

You mention parsing variables to the batch file;

as in :
Quote:
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:
Quote:
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.
Quote:
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.

Wolfnuka 08-02-2016 12:49 PM

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:
Code:
set /p choice="Enter your choice: "
echo. 
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?


All times are GMT -7. The time now is 12:36 AM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
vBulletin Security provided by vBSecurity (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.

vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.