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 8482511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:51:02+00:00 2026-06-10T19:51:02+00:00

I need to modify a text file at runtime but restore its original state

  • 0

I need to modify a text file at runtime but restore its original state later (even if the computer crash).

My program runs in regular sessions. Once a session ended, the original state of that file can be changed, but the original state won’t change at runtime.

There are several instances of this text file with the same name in several directories. My program runs in each directory (but not in parallel), but depending on the directory content’s it does different things. The order of choosing a working directory like this is completely arbitrary.

Since the file’s name is the same in each directory, it seems a good idea to store the backed up file in slightly different places (ie. the parent directory name could be appended to the backup target path).

What I do now is backup and restore the file with a self-written class, and also check at startup if the previous backup for the current directory was properly restored.
But my implementation needs serious refactoring, and now I’m interested if there are libraries already implemented for this kind of task.

edit

version control seems like a good idea, but actually it’s a bit overkill since it requires network connection and often a server. Other VCS need clients to be installed. I would be happier with a pure-python solution, but at least it should be cross-platform, portable and small enough (<10mb for example).

  • 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-06-10T19:51:03+00:00Added an answer on June 10, 2026 at 7:51 pm

    Why not just do what every unix , mac , window file has done for years — create a lockfile/working file concept.

    When a file is selected for edit:

    1. Check to see if there is an active lock or a crashed backup.
    2. If the file is locked or crashed, give a “recover” option
    3. Otherwise, begin editing the file…

    The editing tends to do one or more of a few things:

    1. Copy the original file into a “.%(filename)s.backup”
    2. Create a “.%(filename)s.lock” to prevent others from working on it
    3. When editing is achieved, the lock goes away and the .backup is removed

    Sometimes things are slightly reversed, and the original stays in place while a .backup is the active edit; on success the .backup replaces the original

    If you crash vi or some other text programs on a linux box, you’ll see these files created . note that they usually have a dot(.) prefix so they’re normally hidden on the command line. Word/Powerpoint/etc all do similar things.

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

Sidebar

Related Questions

I need to modify a text file from multiple .NET processes, nothing I've tried
I have a 30000 plus line text file that I need to modify using
I need to modify an MSI file, and I'd like to do it in
I need to modify a column in a SQLite database but I have to
Ok so I have a text file that will change regularly that I need
I need to write a simple terminal-based program that should, Read some text from
I need to write something into a text file's beginning. I have a text
I would like to convert a text file to excel and then modify certain
I have a text file in the assets folder that I need to turn
I need to modify an existing script which uses SED to search and replace

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.