1

I am working on a small python3 project which is a TKinter GUI program, how I can restrict users from deleting the associated files like sqlite3 DB, templates, html etc. until the python script is running. I tried some solution of locking the file into read only which restricts users to delete files but same time it became Un useful for my python script. Is there any way i can keep the file read/write for python script but read only for user who is using the program so files cannot be removed.

Priyanshu
  • 77
  • 8
  • 1
    I don't have the answer to your question, but hidden files could be helpful for you. When a file is hidden, you can usually only see it if you enable a setting. On Windows there's a 'hidden' attribute on files, and on Unix (including Linux and macOS), filenames with a dot at the start (e.g. `.important-data`) are generally not shown. – TheTechRobo the Nerd Mar 15 '23 at 12:53
  • Onto which OS are you planning to deploy the UI? – S3DEV Mar 15 '23 at 15:01
  • If using *nix, [this answer](https://serverfault.com/a/648574) might be a viable option. Aside, the user permissions can be set such that a file cannot be modified (deleted) by unauthorised users. – S3DEV Mar 15 '23 at 21:52
  • @S3DEV, it will deploy in windows – Priyanshu Mar 16 '23 at 09:51
  • I’m afraid the more straight forward option will be as already suggested, making them hidden files. – S3DEV Mar 16 '23 at 11:26
  • Yeah, but I'm looking for a more stringent way – Priyanshu Mar 16 '23 at 12:04

1 Answers1

0

If you open files with with open(), they will be marked as "used" by Python, and you can't delete them.

Example:

import asyncio

async def main():
    with open(r".\fox.txt"):
        await asyncio.sleep(1000)

if __name__ == "__main__":
    asyncio.run(main())
Kalosst0
  • 38
  • 4