3

I have a Desktop application that was saving some data to %AppData%\MyApp\old.txt (roughly 1KB).

I have decided to rename the file that I write to to new.txt.

If I push out this change, customer machines will now have a redundant old.txt on their systems that won't be used for anything.

Is it good practice to add logic to my application like:

if exists("old.txt"):
    if exists("new.txt"):
        delete("old.txt")   
    else:
        rename("old.txt", "new.txt")

...proceed using new.txt
        

Or is it not worth it?

In my case:

  1. The file is small so leaving it on the disk isn't that concerning
  2. In my particular situation, customers aren't even widely using the application yet, so this doesn't really affect many machines in practice

I guess the downside I'm thinking of is eventually this logic will become unnecessary since all machines will use the new file, so at some point, I'd then need to remove this logic. And I guess I don't have a good idea of when that would be.

5
  • 2
    As long as they aren't also running the older version along side your new version, yes, of course, delete it. Dec 1 '20 at 18:22
  • @GrandmasterB I suppose. I added a paragraph to the end of my question explaining my hesitation
    – pushkin
    Dec 1 '20 at 20:30
  • How does your application use these files? What happens if they are missing? Dec 1 '20 at 20:30
  • At what point in the application's life are you deciding to move/rename the file? During installation? During upgrade? During application start-up? Close-down? Dec 1 '20 at 20:31
  • @GregBurghardt The app can start up just fine if the files are missing. The data in the file is just used to restore the window bounds from the last session. I'm deciding to rename the file on application start-up.
    – pushkin
    Dec 1 '20 at 20:39
2

IMHO chances are high it is not worth it - at least in this particular case.

Why?

First, the typical desktop machine gets either a complete reinstall of the operating system and installed software every few years, or it will be sorted out completely at its "end of life" - which means after some time, the file will vanish "automatically".

Second, as you wrote in a comment, the file is just used to restore the window bounds from the last session, so in case there will be an old file and a new file in parallel, chances are pretty low to cause any confusion or errors from this.

Note, if the file would be

  • larger

  • contain more important data

  • could pollute the MyApp folder with waste hindering to find the more important files

  • could disturb debugging scenarios

then the cost/effort balance might become different.

3

You can schedule a scan and delete old files after a transient time to avoid potential backward incompatible issues. So in your current version you handle the case where new file does not work then fails over to the old file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.