Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import ctypes
- from tkinter import *
- from tkinter import filedialog, messagebox
- from tkinter.ttk import *
- from datetime import datetime
- # Estrutura para a função SHFileOperation
- class SHFILEOPSTRUCT(ctypes.Structure):
- _fields_ = [
- ("hwnd", ctypes.c_void_p),
- ("wFunc", ctypes.c_uint),
- ("pFrom", ctypes.c_wchar_p),
- ("pTo", ctypes.c_wchar_p),
- ("fFlags", ctypes.c_uint),
- ("fAnyOperationsAborted", ctypes.c_int),
- ("hNameMappings", ctypes.c_void_p),
- ("lpszProgressTitle", ctypes.c_wchar_p)
- ]
- # Constantes para o tipo de operação
- FO_COPY = 0x0002
- FO_MOVE = 0x0001
- # Flags para controlar o comportamento
- FOF_NOCONFIRMATION = 0x0010
- FOF_SILENT = 0x0004 # Sem diálogos de erro
- def native_copy_move(src, dst, move=False):
- operation = FO_MOVE if move else FO_COPY
- file_op = SHFILEOPSTRUCT()
- file_op.wFunc = operation
- # Adiciona caracteres nulos no final para compatibilidade com SHFileOperation
- file_op.pFrom = src.replace("/", "\\") + '\0\0'
- file_op.pTo = dst.replace("/", "\\") + '\0\0'
- file_op.fFlags = FOF_NOCONFIRMATION
- result = ctypes.windll.shell32.SHFileOperationW(ctypes.byref(file_op))
- if result != 0:
- messagebox.showerror("Erro", "Falha na operação de cópia/movimentação.")
- else:
- now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
- log_entry = f"{now} - {'Movido' if move else 'Copiado'}: {src} -> {dst}"
- log_text.insert(END, log_entry + "\n")
- log_text.see(END)
- def start_copy_move_native():
- src_paths = [path.strip() for path in src_entry.get().strip().split(";") if path.strip()]
- dst_folder = dst_entry.get().strip()
- if not src_paths:
- messagebox.showwarning("Aviso", "É necessário escolher um ou mais arquivos ou pastas para copiar ou mover.")
- return
- if not dst_folder or not os.path.exists(dst_folder):
- messagebox.showerror("Erro", "O destino especificado não existe.")
- return
- for src in src_paths:
- if os.path.exists(src):
- native_copy_move(src, dst_folder, move=(operation.get() == "move"))
- else:
- # Mensagem removida para evitar alertas desnecessários após uma execução bem-sucedida.
- pass
- messagebox.showinfo("Sucesso", f"{'Movido' if operation.get() == 'move' else 'Copiado'} com sucesso!")
- os.startfile(dst_folder)
- def select_src():
- src_files = filedialog.askopenfilenames()
- src_entry.delete(0, END)
- src_entry.insert(END, ";".join(src_files) + ";")
- def select_folder():
- folder = filedialog.askdirectory()
- src_entry.insert(END, folder + ";")
- def select_dst():
- dst_folder = filedialog.askdirectory()
- dst_entry.delete(0, END)
- dst_entry.insert(0, dst_folder)
- def show_about():
- messagebox.showinfo("Sobre", "GigaCopy 2.8 - Programa para copiar ou mover múltiplos arquivos e pastas usando a barra de progresso padrão do Windows\n21/11/2024, Mizuno")
- def exit_program():
- window.quit()
- # Configuração da janela
- window = Tk()
- window.title("GigaCopy 2.8 com Barra de Progresso Nativa")
- window.geometry('710x440')
- window.eval('tk::PlaceWindow . center')
- window.resizable(False, False)
- menu_bar = Menu(window)
- actions_menu = Menu(menu_bar, tearoff=0)
- actions_menu.add_command(label="Adicionar arquivos", command=select_src)
- actions_menu.add_command(label="Adicionar pasta", command=select_folder)
- actions_menu.add_separator()
- actions_menu.add_command(label="Sobre", command=show_about)
- actions_menu.add_command(label="Sair", command=exit_program)
- menu_bar.add_cascade(label="Ações", menu=actions_menu)
- window.config(menu=menu_bar)
- operation = StringVar(value="copy")
- Label(window, text="Origem:").grid(row=0, column=0, padx=10, pady=5, sticky=W)
- src_entry = Entry(window, width=52)
- src_entry.grid(row=0, column=1, padx=10, pady=5, columnspan=2, sticky=W)
- Label(window, text="Destino:").grid(row=1, column=0, padx=10, pady=5, sticky=W)
- dst_entry = Entry(window, width=52)
- dst_entry.grid(row=1, column=1, padx=10, pady=5, sticky=W)
- Button(window, text="Escolher destino", command=select_dst, width=15).grid(row=1, column=2, padx=5, sticky=W)
- Label(window, text="Operação:").grid(row=2, column=0, padx=10, pady=5, sticky=W)
- Radiobutton(window, text="Copiar", variable=operation, value="copy").grid(row=2, column=1, sticky=W, padx=5)
- Radiobutton(window, text="Mover", variable=operation, value="move").grid(row=2, column=1, padx=130, sticky=W)
- button = Button(window, text="Iniciar", command=start_copy_move_native, width=10)
- button.grid(row=3, column=1, padx=10, pady=10, sticky=W)
- log_text = Text(window, height=15, width=85, state='normal')
- log_text.grid(row=4, column=0, columnspan=4, padx=10, pady=10)
- window.mainloop()
Add Comment
Please, Sign In to add comment