0

I am working on some project.

I want that I lock some file whenever I run the script.

So that noone can delete/modify the file.

  • 6
    Does this answer your question? [Locking a file in Python](https://stackoverflow.com/questions/489861/locking-a-file-in-python) – Abhyudaya Sharma Jan 17 '21 at 17:20
  • To lock a file you specify a sharemode. https://www.oreilly.com/library/view/python-programming-on/1565926218/re32.html – user14797724 Jan 17 '21 at 18:42
  • https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew . The first link is totally stupid answers. **sharemode**. – user14797724 Jan 18 '21 at 02:02

1 Answers1

0

Use os module for this purpose.

import os
file_path = 'D:\\file.txt'    # your file path
os.system(f'echo y| cacls {file_path} /P everyone:n')

I hope you got it.