Write a specific line from a text file to another text file using VBS?
I'm currently using batch to create an online updater. I have a file containing the current online version, and I want to copy the download link from the second line to another file so that another batch script can open it. Since this is almost impossible in batch, I would like to implement this read-and-rewrite script in VBS.
If anyone is interested, the batch script is here:
echo off set /p systemversion=<systemversion.dat cd downloads if exist "currentonlineversion.dat" del currentonlineversion.dat cd.. title BatchOs Downloader cls echo Please move the downloaded file to the opened folder! echo Press any key to begin the download. pause >nul ::open.vbs öffnet den downloads Ordner:: start open.vbs start [Downloadlink zu currentonlineversion.dat mit Version und link] cd downloads :waitloop if exist "currentonlineversion.dat" goto checkforpossibleupdate goto waitloop :checkforpossibleupdate set /p onlineversion=<currentonlineversion.dat echo Checking for updates... echo. if not %systemversion%==%onlineversion% goto downloadupdate
Looking forward to your answers.
… again one of the tries to make his own "OS" by batch
well, you're a bloody beginner who's deceived…🤗
Batch is one of the most barbaric languages ​​you can do. (unless you are looking for an extreme challenge) . My very special playground: ( so you can see what "restrictions" are necessary to control Batch in a way )
The VBScript frame is not necessary. especially since VBS is technically at the stand of 2009 and on modern systems has increasingly problems with certain file names and some of the snap points of M$ have been deactivated…
But back to your batch:
A certain line from a file reading Skip indicates how many lines (with content) are skipped when reading: (for/f ignores empty lines)
demo.cmd
…with the whole file
Demo.cmd
but why the circumstances?
My interpretation of "CurrentOnlineVersion.dat" … so saves I will make you a lot of individual variable assignments later with a slide.
CurrentOnlineVersion.dat
OfflineDemo.cmd
directlyOnlineRead in.cmd
actually sausage, from which data is collected. in Batch, the For/f-loop is the hub for all data exchange
whether you relate data from a file or from a program output is irrelevant…
display file with curl directly:
You can also use this command in for/f (Leerlines are ignored):
something else to your pardon:
with pushd "directory" and pope you can just get back to where you came from:
rem to the download folder of the current user
and if the For/f-Loop burns your brain away, you know why Powershell was invented and replaced Cmd as Console as standard from Windows 10.
But that's another story…
Do not plug too much energy into Batch/Cmd anymore. In the next few years, Batch may disappear completely. Microsoft has already sent one of the most important batch commands (WMIC.exe) from the Windows 11 developer versions. In this way, deep system data for Batch are no longer directly accessible… so Batch is in the A****
If you want to work safely with ConsoleScript, learn Powershell.
Thanks for the explanation, did a lot with Batch some time ago and wanted to finish a project. Thanks also for using Curl, so I could just automate the download so you don’t have to manually move the file. Very well explained.