Force Overwrite in Os.Rename

后端 未结 7 1631
北荒
北荒 2020-11-30 05:10

Is it possible to force a rename os.rename to overwrite another file if it already exists? For example in the code below if the file Tests.csv already exists it would be re

相关标签:
7条回答
  • 2020-11-30 06:10

    On Unix, if dst exists and is a file, it will be replaced silently if the user has permission. The operation may fail on some Unix flavors if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement). On Windows, if dst already exists, OSError will be raised even if it is a file; there may be no way to implement an atomic rename when dst names an existing file. http://docs.python.org/library/os.html#os.rename

    0 讨论(0)
提交回复
热议问题