1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: batch programming: reading and writing from/to text file?

Discussion in 'Software Development' started by sternkanz, Oct 8, 2008.

Thread Status:
Not open for further replies.
  1. sternkanz

    sternkanz Thread Starter

    Joined:
    Oct 3, 2008
    Messages:
    21
    Hi,

    I would like to have a text file that stores a number, lets say 2000. I want my batch script to grab the number from that file, and put it into a variable. The script will then do stuff with that variable and once it is finished, add 1 to it (don't know how easy that bit is). Then I want the script to write this number (2001) back into the text file, overwriting the old number.

    So basically the contents of the text file would go from 2000, to 2001, to 2002, etc each time the batch file is run.

    Would anyone be able to point in the right direction for this?

    Any help is highly appreciated.
     
  2. devil_himself

    devil_himself

    Joined:
    Apr 7, 2007
    Messages:
    4,910
    Code:
    @for /f %%a in (file.txt) do @set /a var=%%a+1
    echo.%var%>file.txt
    
     
  3. sternkanz

    sternkanz Thread Starter

    Joined:
    Oct 3, 2008
    Messages:
    21
    Thanks! Once again you guys are awesome. :)
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/757242

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice