Last active
March 29, 2021 11:54
-
-
Save Theasker/ccd02663ae32277ff44750483ce5145d to your computer and use it in GitHub Desktop.
Rename files from directory. Program done with Python and tkinter (working)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tkinter import * | |
| from tkinter import ttk | |
| import os | |
| class MyRenamer: | |
| def __init__ (self, window): | |
| window.title("Renombrador de archivos") | |
| self.dir = "" | |
| self.lbl = Label(window, text="Selecciona un directorio") | |
| self.lbl.grid(row=0, column=0, padx=5, pady=5) | |
| self.btn = Button(window, text="Selecciona un directorio", command=self.chose_dir) | |
| self.btn.grid(row=0, column=1, padx=5, pady=5) | |
| self.lbl_text = Label(window, text="Escribe texto a borrar") | |
| self.lbl_text.grid(row=1, column=0, padx=5, pady=5) | |
| self.text = Entry(window, width=25) | |
| self.text.grid(row=1, column=1, padx=5, pady=5) | |
| self.lbl_info = Label(window, text="") | |
| self.lbl_info.grid(row=2, column=0, columnspan=3, padx=5, pady=5) | |
| self.treeview = ttk.Treeview(window) | |
| self.treeview.grid(row=3, column=0, columnspan=3, padx=5, pady=5) | |
| def chose_dir(self): | |
| self.dir = filedialog.askdirectory() | |
| # Cambiamos el dir activo | |
| os.chdir(self.dir) | |
| self.lbl_info["text"] = self.dir | |
| self.recorrer() | |
| def recorrer(self): | |
| # recorro los ficheros del directorio | |
| for file in os.listdir(self.dir): | |
| print(f"{self.dir}{file}") | |
| # os.rename(file, f"{self.dir}{file}") | |
| print("-------------------------------------") | |
| with os.scandir(self.dir) as ficheros: | |
| for fichero in ficheros: | |
| print(fichero.path) | |
| if __name__ == "__main__": | |
| root = Tk() | |
| my_gui = MyRenamer(root) | |
| root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment