I'm almost there! I have a script which will search through a txt file (list.txt) to the very last line (or record).
This last line is always a decimal number between 1 and 1000.
I'd like to be able to assign this to a value in a batch file, but cannot understand how to import this one line of
data from the file.
I'm building a rudimentary CD database, all I want is the disk number (that begs the question above).
1) open the data file
2) read the last entry (it is the disk number)
3) increment the number by 1
4) write this number to the file
5) send the disk directory contents to the file
6) write the same disk number to the file.
(That way when I search for the disk number, each disk's directory is between the two same numbers)
I've got everything but item (2). Right now I have to enter the next disk number manually and I would like to
automate this.
I'm having to learn the batch file language after all these years. I usually do 'most everything in Turbo Basic (yes I am THAT old), but every Basic I find will only export filenames in 8.3. Even when SHELLing to a command file. Ahhhrghh!
Would really appreciate some help, I thank you in advance
-- Doc
Assigning the last line of a txt file to a value
Moderator: DosItHelp
Re: Assigning the last line of a txt file to a value
If only in the last line a number and nothing else?
If yes then is this the solution:
If yes then is this the solution:
Code: Select all
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
if not exist ich.txt echo 0 >ich.txt
for /f %%a in (ich.txt) do set last=%%a
set /a last+=1
echo !last!>>ich.txt
Re: Assigning the last line of a txt file to a value
Thanks! I'll give this a try. Doesn't seem to be a book or list anywhere of all the Batch commands. Not i one place, anyway. I've got three copies of my GWBASIC and TURBO BASIC books, so I can usually lay my hands on one within a few minutes. (I'm organizationally challenged, as I like to say).
Thanks again,
-- Doc
Thanks again,
-- Doc
Re: Assigning the last line of a txt file to a value
Please see this site: http://www.dostips.com/DosCommandIndex.php
Also see the different other topics in this forum.
Trebor68
Also see the different other topics in this forum.
Trebor68
Re: Assigning the last line of a txt file to a value
Thanks, Trebor! Just for what I've been looking.
This is a an Helluva good support forum. Maybe one day I will be able to answer rather than just ask.
Yours for Better Television,
== Doc
Remember, a preposition is the wrong thing to end a sentence with - and That is something up with which I shall not put!
This is a an Helluva good support forum. Maybe one day I will be able to answer rather than just ask.
Yours for Better Television,
== Doc
Remember, a preposition is the wrong thing to end a sentence with - and That is something up with which I shall not put!