Advertisement
DarkPotatoKing

Python Change File Read-only status

Aug 27th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. #python how to change File Attributes (Read and Write)
  2. #taken from http://techarttiki.blogspot.com/2008/08/read-only-windows-files-with-python.html
  3.  
  4. import os, stat
  5. myFile = r'TestFile.txt'
  6.  
  7. fileAtt = os.stat(myFile)[0]
  8. if (not fileAtt & stat.S_IWRITE):
  9.    # File is read-only, so make it writeable
  10.    os.chmod(myFile, stat.S_IWRITE)
  11. else:
  12.    # File is writeable, so make it read-only
  13.    os.chmod(myFile, stat.S_IREAD)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement