Questions: (1) the program can not display properly handled the number of files, see chart shown in red underline:
(2) failed to extract hidden files
Hope who can teach me how to solve the two problems above,
My code:
Renamer_V1. Py:
the import the OSThe from tkinter import filedialog
The import tkinter as tk
The from tkinter import Button
Def rename () :
N=0
File_path=filedialog. Askdirectory (title='ReNamer')
File_lists=OS. Listdir (file_path)
For file in file_lists. Copy () :
Oldname=file_path + OS. Sep + file
If OS. Path. Isdir (oldname) :
The continue
The else:
Newname=file_path + OS. Sep + '(' + STR (n + 1) +') '+ file
OS. Rename (oldname, newname)
N +=1
Return n
Root=tk. Tk ()
Root. Geometry (" 550 x200 ")
Label=tk. Label (root, the font=(" Arial Bold ", 15),
Text='both Please select a directory to rename files in the folder:')
Label. Pack ()
BTN=Button (root, the font=(" Arial ", 15), bg='orange', the text="Click Me", the command=rename)
BTN. Pack ()
Label=tk. Label (root, text=STR (rename) + 'file (s) renamed.')
Label. Pack ()
Root. Mainloop ()
CodePudding user response:
I changed it once, but always rename files under this quantity is zero, why is this so? How to let it show the correct number?
the import the OSThe from tkinter import filedialog
The import tkinter as tk
The from tkinter import Button
The class ReName () :
Def __init__ (self) :
The self. The n=0
Def rename (self) :
File_path=filedialog. Askdirectory (title='ReNamer')
File_lists=OS. Listdir (file_path)
For file in file_lists. Copy () :
Oldname=file_path + OS. Sep + file
If OS. Path. Isdir (oldname) :
The continue
The else:
Newname=file_path + OS. Sep + '(' + STR (self. The n + 1) +') '+ file
OS. Rename (oldname, newname)
The self. The n +=1
Print (self. N)
Ins=ReName ()
Root=tk. Tk ()
Root. Geometry (" 550 x200 ")
Label=tk. Label (root, the font=(" Arial Bold ", 15),
Text='both Please select a directory to rename files in the folder:')
Label. Pack ()
BTN=Button (root, the font=(" Arial ", 15), bg='orange', the text="Click Me", the command=ins. Rename)
BTN. Pack ()
Print (ins. N)
Label=tk. Label (root, text=STR (ins. N) + 'file (s) renamed.')
Label. Config (text=ins. N)
Root. Mainloop ()