Need to increment data read from txt file

September 9, 2011 at 12:38:50
Specs: Windows XP, AMD 3 core / 3G
I have a .txt file, of which the last entry in the file is a number. (the rest of the data is text)
I need to read that number, increment it by 1, and then write that number to the file as the next entry (and then I write some more data and the number again).
Basically I write file directories to the .txt file, and starts and ends each listing with a number which is the disk number. As I add directory lists to the file, I need to increment that number by 1.

I've got just about everything else figured out and written, but I would sure like to automate this one part of the task.

The main reason I am using batch files rather than Basic (OK, I know, but after 30 years, it's hard to break an old habit).

I wrote what a needed to do in Basic, but using basic and even shelling to a batch file, the file directories are always 8.3. SO in order to get full filenames, I've for to do the task with batch files.

I'm on chapter 3 of learning Visual Basic, but I need this program now, not in the 10 years it will take me to master VB.

Hope this makes sense, thanks in advance for any help.

-- Doc

See More: Need to increment data read from txt file

Report •

September 9, 2011 at 13:22:53
You can extract that number out of the text file see here:

Then load it into a variable with

set /p next_number_variable=<textfile_with_number_only.txt

then do this to increment the number

set /a next_number_variable=<number from file> + 1


echo next_number_variable >> textfile.txt

Report •

September 9, 2011 at 15:03:58
Wow! Thanks for the speedy reply. I figured I had a couple of days' wait. I'll give this a try now. Thanks very much.
-- Doc

Report •

September 12, 2011 at 08:53:33
No problem drdumont. I just posted a similar answer to another question that might be useful to you. Here's the link:

Report •

Related Solutions

Ask Question