Reading a website and saving as variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Osmium Programming
Posts: 14
Joined: 16 Oct 2017 20:15

Reading a website and saving as variable

#1 Post by Osmium Programming » 16 Apr 2018 21:32

I want to create an update checker that checks a raw pastebin file that I will make that contains the current version of the program. If it matches the installed program's version, great. If not, it will read the same pastebin for the link to the current version and update it.

The only thing that confuses me is how I can read the website.

IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Re: Reading a website and saving as variable

#2 Post by IcarusLives » 16 Apr 2018 22:27

Here is a solution you could use! Plus, you'll end up with the BreakOut Batch Arcade Game I made a while back. Never released it because I was too shy. (Everyone here seems to be a genius :shock: )

In this code there is a function named :download <website> <outputName.fileExtension>
(I don't think this is truly downloading, considering it copies whatever is on the webpage, and creates a file with the contents in it.)

This is what I use to get the information off of websites, mostly RAW pastebins.

After calling :download %website% %websiteFileName% we collect each line parsed from the created~~ file and create an array !file[%lines%]!

After that you can display the entire array using a for loop ^^

Does this help?

Code: Select all

@echo off & setlocal enableDelayedExpansion


set "website=https://pastebin.com/raw/r5PasAJN"
set "websiteFileName=BreakOut_Batch_Arcade_Game.bat"

call :download %website% %websiteFileName%

rem create an array of each line in the file
for /f "tokens=* delims=" %%a in (%websiteFileName%) do (
	set /a "lines+=1"
	set "file[!lines!]=%%~a"
)

rem display the array/file data
for /l %%a in (1,1,%lines%) do echo=!file[%%a]!
pause & exit

:Download <url> <File>
    Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','%2')"
goto :eof

Osmium Programming
Posts: 14
Joined: 16 Oct 2017 20:15

Re: Reading a website and saving as variable

#3 Post by Osmium Programming » 16 May 2018 19:24

Yes!! This is super cool! Thanks so much, this really helps.

Post Reply