-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_renamer.py
More file actions
24 lines (22 loc) · 835 Bytes
/
auto_renamer.py
File metadata and controls
24 lines (22 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Auto File Renamer
created and published by atrx07
Usage: python auto_renamer.py /path/to/folder prefix
Example: python auto_renamer.py ./downloads file_
"""
import os, sys
def auto_rename(folder, prefix="file_"):
files = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder,f))]
files.sort()
for i, fname in enumerate(files, start=1):
ext = os.path.splitext(fname)[1]
new = f"{prefix}{i}{ext}"
os.rename(os.path.join(folder, fname), os.path.join(folder, new))
print(f"Renamed {len(files)} files in {folder}")
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python auto_renamer.py /path/to/folder [prefix]")
else:
folder = sys.argv[1]
prefix = sys.argv[2] if len(sys.argv) > 2 else "file_"
auto_rename(folder, prefix)