I need to make a file readable and writable in python. Currently the file is read-only. I am running on a Windows machine. I run the following code:
os.chmod(projectPath, stat.S_IWRITE | stat.S_IREAD)
on a file that needs to be read/write. But when I try to execute the file that needs to be read write, I get the following:
ISDEV : fatal error -2200: Could not overwrite file C:\WINDOWS\Temp\STixInstaller\STixInstallShield.ism
So obviously, it is not making the file read/write. I then check the file permissions and it is still read-only.
Any ideas why this fails or if there is an easier way to do this I am missing?
I think you only need the stat.S_IWRITE mode. I just ran a test with this code
def main():
path = "C:\\temp\\log.txt"
os.chmod(path, stat.S_IWRITE)
And it set a file that was read only to not read only, where as when I ran it with S_IREAD instead, it set it back to read only
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With