Skip to content

Commit 27db560

Browse files
authored
added [script]:file-renamer-by-time
1 parent 08b7bdd commit 27db560

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Rename_by_time/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
from math import log10
3+
4+
files=os.listdir(".")
5+
6+
files.sort(key=lambda x: os.path.getmtime(x))
7+
# print(files) # list index 0 hold the oldest file
8+
digits=int(log10(len(files)))+1
9+
10+
print(f"\nPlease verify the new file names for accuracy: press 'p' to review the file names, or 'y'/'Y' to proceed with the renaming process. Press any other key to exit the program.\n")
11+
n=input()
12+
13+
if(n=="y" or n=="Y" or n=="p"):
14+
rename,hidden=0,0
15+
for i in range(len(files)-1):
16+
if(files[i][0]=="."):
17+
hidden+=1
18+
continue
19+
20+
if "_" in files[i] and files[i][0]!="_":
21+
index=files[i].find("_")
22+
isNum=files[index-1]
23+
24+
if(isNum >="0" and isNum<="9"):
25+
oldName=files[i][index+1:]
26+
else:
27+
oldName=files[i]
28+
else:
29+
oldName=files[i]
30+
31+
rename+=1
32+
newfile_name=f"{str(rename).zfill(digits)}_{oldName}"
33+
34+
if(n=="p"):
35+
print(f"{oldName} --> {newfile_name}")
36+
else:
37+
os.rename(oldName,newfile_name)
38+
print("File renaming successful.\n")
39+
print(f"\nNumber of hidden files are {hidden}. For safety purpose, they will be kept unchanged.")
40+
41+
else:
42+
print("File renaming cancel.")
43+
exit(0)

Rename_by_time/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Rename Files by Time- The most powerful renamer
2+
This software can rename your all current directory files in ascending order based on recently modified time. Oldest file named with 01_oldname .... like this
3+
4+
# Video Demo
5+
6+
## Note: pls turn audio for a clear understanding
7+
8+
https://github.com/Rancho2002/rename-by-time/assets/92109154/0ff611ff-d81b-46bf-b49f-86d2775638d6

0 commit comments

Comments
 (0)