-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiremgari-old
More file actions
38 lines (30 loc) · 823 Bytes
/
iremgari-old
File metadata and controls
38 lines (30 loc) · 823 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# For Python versions before 3.11
import os
from sys import argv
def eligible(name):
# EDIT ME
# Determine whether a file should be renamed.
return False
def process(name):
# EDIT ME
# Return the new name given an old name.
return name
# TODO: guard against overwrites
def rename(path, dryrun=False):
print(path)
for oldname in os.listdir(path):
if os.path.isfile(os.path.join(path, oldname)) and eligible(oldname):
newname = process(oldname)
print(f"{oldname} -> {newname}")
if not dryrun:
os.rename(os.path.join(path, oldname), os.path.join(path, newname))
dryrun_arg = False
path_arg = "."
# TODO: multiple arguments at once
if len(argv) >= 2:
if argv[1] == "-d":
dryrun_arg = True
else:
path_arg = os.path.join(path_arg, argv[1])
rename(path_arg, dryrun_arg)