0

As the title suggests, is there a builtin library for moving a file and replacing an existing file if it exists?

I tried os.rename(path1, path2), but that doesn't seem to handle overwriting existing files.

Working with a pycom gpy, if that matters.

Thanks in advance

Diaonic
  • 151
  • 1
  • 15

1 Answers1

1

POSIX semantics require overwriting the target file in this case (and even atomically). So, "pycom gpy" seems to have a bug (or misfeature) in that regard. As a workaround, you can remove the target file with os.remove(path2) before rename.

pfalcon
  • 6,724
  • 4
  • 35
  • 43