-
Notifications
You must be signed in to change notification settings - Fork 3
/
mv-date
executable file
·36 lines (32 loc) · 1.05 KB
/
mv-date
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
#!/usr/bin/env python3
# Rename files using a transformation that supports datetimes.
import argparse
import functools
import sys
from typing import Optional
import mv_sed
def main() -> Optional[str]:
parser = argparse.ArgumentParser(description=(
"Renames files using a transformation that supports datetimes."
))
parser.add_argument("-n", "--dry-run", action="store_true",
help="don't actually rename anything")
parser.add_argument("pattern", help="Pattern to match")
parser.add_argument("replacement", help="Replacement")
parser.add_argument("files", nargs="+", help="filename")
args = parser.parse_args()
transformation = functools.partial(
mv_sed.transform_date,
[(args.pattern, args.replacement)],
)
try:
mv_sed.mv_transform(
dry_run=args.dry_run,
transformation=transformation,
files=args.files,
)
except mv_sed.Error as e:
return f"{parser.prog}: {e}"
return None
if __name__ == "__main__":
sys.exit(main())