0

An executable python 2.7 script named RenewGR does stuff then as a final step is supposed to delete itself (the executable file) via the line os.remove("RenewGR"). In Mac OS X and Linux environments it works as expected: the executable runs and then disappears. When compiled and run under Windows 10 the final step fails with

Traceback (most recent call last):
  File "RenewGR.py", line 64, in <module>
    os.remove("RenewGR.exe")
WindowsError: [Error 5] Access is denied: 'RenewGR.exe'
[8132] Failed to execute script RenewGR.

When pyinstaller creates the executable RenewGR.exe it put it into the dist folder. By default that folder and its contents are read-only. When I change the properties of the dist folder to unset read-only for it and its contents and apply that change dist promptly reverts to read-only.

Is it possible to have an excutable file delete itself under Windows? If so, how can I code that?

Barry
  • 643
  • 1
  • 6
  • 9

0 Answers0