I'm currently programming a tool for downloading stuff from the internet. For the user, it is possible to specify a download folder where all downloaded files are stored.

Assume that the program realizes that it should save the download to a file that already exists - how should it react.

Intuitively I would say that the program should come up with some kind of dialog asking the user whether it should replace the existing file, save the download to another file or ...

However, due to the automatic execution, it is NOT possible to ask the user what should be done (replace, use another file, log error, ...).

So what should be done in such a case?

  • Is there a configuration GUI or does it always run headless?
    – Barnyard
    Jul 18, 2019 at 17:18
  • Is there any user configuration at all? I'd see this being an issue where people might want it to behave differently based on what they're using the tool to accomplish (e.g. always overwrite with latest, never replace if file already exists, save with a modified file name). Jul 18, 2019 at 18:16
  • @Barnyard Both. There is a GUI but it can run in headless mode too.
    – quant
    Jul 19, 2019 at 9:03
  • 1
    @quant The answer by topenion covers most of what I would have said. If it is downloading automatically in the background, then I assume the user has to set up that recurring download at some point. If that is the case, then you could use the safe (no overwrite) behavior by default, but have an option to enable overwriting files for that recurring set of downloads.
    – Barnyard
    Jul 19, 2019 at 16:30

2 Answers 2


There are a few things that you could do.

  • If the files are large and bandwidth is a concern, you could try to match size and filetype to see if it is actually a duplicate. In that case just skip it.

  • If you know beforehand the types of file will be download and they happen to be too important to be missed. Just save it while appending time in filename.

  • If you are also the source of the files, just have a provision of the checksums you could compare with existing filename.

  • When in doubt, lean towards keeping the file after renaming. Overwriting should happen only if you are fully sure that it should rather be overwritten.

Employ a strategy with the mix; favour renaming, skip is second fiddle, overwriting is "dangerous waters". Whatever you do keep the logs of what you renamed, skipped or overwrote. Additionaly , giving user setting or config option is a big plus. Even better would be a way to revert the changes you made.

In Short : Employ a mixed strategy, keep the logs

  • 1
    +1.Note to OP: re. "giving user setting or config option is a big plus"... even when being run "headless", there can be config options that the user sets ahead of time to determine how an unattended operation should behave if it encounters duplicate names.
    – TripeHound
    Jul 19, 2019 at 13:37

Yes, def a settings thing. You might allow the user to have a setting switch that states "Overwrite Existing" [yes] [no]. IF there is no settings option, THEN have a dialog that states "File already exists, would you like to rename?" If that is not possible, then you might have documentation that explicitly states "Files must have unique names because..."

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.