Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 653227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:21:31+00:00 2026-05-13T22:21:31+00:00

I want my program to be able to write files in a sequential format,

  • 0

I want my program to be able to write files in a sequential format, ie: file1.txt, file2.txt, file3.txt. It is only meant to write a single file upon execution of the code. It can’t overwrite any existing files, and it MUST be created. I’m stumped.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:21:31+00:00Added an answer on May 13, 2026 at 10:21 pm

    Two choices:

    1. Counter File.

    2. Check the directory.

    Counter File.

    with open("thecounter.data","r") as counter:
        count= int( counter.read() )
    
    count += 1
    

    Each time you create a new file, you also rewrite the counter file with the
    appropriate number. Very, very fast. However, it’s theoretically possible to
    get the two out of synch. in the event of a crash.

    You can also make the counter file slightly smarter by making it a small piece of
    Python code.

    settings= {}
    execfile( "thecounter.py", settings )
    count = settings['count']
    

    Then, when you update the file, you write a little piece of Python code: count = someNumber. You can add comments and other markers to this file to simplify your bookkeeping.

    Check the directory.

    import os
    def numbers( path ):
        for filename in os.listdir(path):
            name, _ = os.path.splitext()
            yield int(name[4:])
    count = max( numbers( '/path/to/files' ) )
    
    count += 1
    

    Slower. Never has a synchronization problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a little program which is able to work with Google
I want to save my program's DataModel objects to a file, and be able
I want to be able to distribute a program in Linux without distributing the
In the program I am writing, I want to be able to import CSV
I am creating a c++ program, but I want to be able to offer
I have a closed-source 3rd party program, and I want to be able to
I'm having a complete program, but now, I want it to be able to
In my program i want the user to be able to take some images
I want to learn how to read .txt files in C , line by
I want to be able to split up my bin and my code files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.