-1

I have a program that creates a file and writes files to it. But it always displays this:

error: PermissionError: [Errno 13] Permission denied: 'C:/Users/Theo/Documents/testfolder'

How can I make it that it asks the user if they want to give this program Admin privileges and continues as normal?

Here is my code:

from tkinter import *
from tkinter import filedialog
import os
import subprocess

def getFile():
    save_path = filedialog.askdirectory(title="Where to create ISO file?")

    final_name = name.get()+".iso"
    completeName = os.path.join(save_path, final_name)
    open(str(completeName), 'x')
    src_path = filedialog.askdirectory(title="Choose your directrory")
    final_src = os.listdir(src_path)
    with open(save_path, 'w') as f:
        f.write(final_src)

root = Tk()
name = Entry(root)
name.pack()
button = Button(root,text="Start",command=getFile)

button.pack()
root.mainloop()
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • This is old, but may answer your question: https://stackoverflow.com/questions/19672352/how-to-run-script-with-elevated-privilege-on-windows – Cargo23 Oct 05 '22 at 14:47
  • Sounds like an XY problem. If you are not user `Theo`, why are you trying to write to their user folder? Or if you _are_ user `Theo`, shouldn't you just change ownership or permissions on `Documents/testfolder`? – Thomas Oct 05 '22 at 14:49
  • @Thomas Im making a program that writes files form a folder to an ISO file. – Canofeggs 5410 Oct 05 '22 at 15:32

1 Answers1

0

Sounds like Errno 13 Permission denied Python. I remember going through the same thing when I was doing tkinter. Hope it helps.