Do csg copy a file and rename it then( OS, Shutil)

Asked

Viewed 40 times

0

I’m making an app where I need to copy an image from inside the user’s pc and then play the image in a folder inside a directory that is the program called "/Images". However, even without errors this does not happen just nothing happens, I have already used "shutil.copy" and "shutil.copy2" in both of them nothing occurs, neither error, nor the image and copied and using "shutil.copyfile" Give the following error "Permission Denied", or "Permission denied". Does anyone know a way to fix the mistake, or make it work ?

The program itself has almost 1000 lines, but the part that I think matters to this problem is from line 929 to 980 (that part Aki)

    def ImageSelect(self):
        self.master.filename = filedialog.askopenfilename(title="Select a Photo", filetypes=(("png files(RECOMENDADA)", "*.png"),("all files", "*.*")))
        self.top.focus()
        self.word = self.master.filename.split("/")
        self.caminho = self.master.filename.split(self.word[-1])
        print("----------------")
        print(self.word[-1])
        print(self.caminho[0])
        print("----------------")



    def Salvar_criado(self):

        Nome = self.entryN1.get()
        Telefone = self.entryT1.get()
        Endereco = self.entryE1.get()
        Funcao = self.entryR1.get()
        Idade = self.entryI1.get()

        if Nome in EQUIPI_DI:
            tkinter.messagebox.showinfo("Não foi possível realizar a ação desejada!",
                                        "Nome já existente no registro! Porfavor diferencie este contato do outro, ou, caso esteja querendo edita-lo, vá na opção editar.")
        else:
            if Nome == "" or Nome == " ":
                tkinter.messagebox.showerror("ERROR", "Nome Inválido")
            else:
                opcao = tkinter.messagebox.askyesno("", "Você deseja salvar as alterações?", parent=self.top)
                if opcao > 0:
                    EQUIPI_DI[Nome] = {
                        'numero': Telefone,
                        'endereco': Endereco,
                        'funcao': Funcao,
                        "idade": Idade,
                    }

                    texto = open("[TEAM]" + Nome + ".txt", "x")
                    try:
                        shutil.copyfile(os.path.join(self.caminho[0], self.word[-1]), os.path.join("/Images", self.word[-1]))
                        os.rename(f"/Images/{self.word[-1]}", f"/Images/{Nome}"+"[TEAM]"+".png")
                        print("______feito")
                    except Exception as error:
                        print(error)
                        pass

                    self.top.destroy()
                    self.master.destroy()
                    Window1.hospital_window(self.master)
                    salvar()
                else:
                    pass

I appreciate any help.

  • 1

    I don’t have such an advanced knowledge of Python, but if it just doesn’t happen like you say, and we see functions in your code, we already check if you are calling the functions?

  • So I put the print on it, and it works, so much so that if I put it on instead of shutil.copy, I put shutil.copyfile on a denied permission error. I really don’t know what pal ta giving kkk

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.