Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1b8b7b2

Browse files
Merge pull request avinashkranjan#2313 from Rancho2002/file-renamer
Added [script]: rename-file by modified time
2 parents e6a255a + 69086ab commit 1b8b7b2

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

‎Rename_by_time/main.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
17+
oldname=files[i]
18+
19+
if(files[i][0]=="."):
20+
hidden+=1
21+
continue
22+
23+
if "_" in files[i] and files[i][0]!="_":
24+
index=files[i].find("_")
25+
isNum=files[index-1]
26+
27+
if(isNum >="0" and isNum<="9"):
28+
tempOld=files[i][index+1:]
29+
else:
30+
tempOld=files[i]
31+
else:
32+
tempOld=files[i]
33+
34+
rename+=1
35+
newfile_name=f"{str(rename).zfill(digits)}_{tempOld}"
36+
37+
if(n=="p"):
38+
print(f"{tempOld} --> {newfile_name}")
39+
else:
40+
os.rename(oldname,newfile_name)
41+
42+
print(f"\nNumber of hidden files are {hidden}. For safety purpose, they will be kept unchanged.")
43+
44+
else:
45+
print("File renaming cancel.")
46+
exit(0)
47+
48+
if n=="y" or n=="Y":
49+
print("\nFile renaming successful.")

‎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+
7+
https://github.com/Rancho2002/Amazing-Python-Scripts/assets/92109154/12ea31cd-e257-499f-bb3a-6491f4cf2c67
8+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /