-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename_imgs.py
More file actions
32 lines (27 loc) · 943 Bytes
/
rename_imgs.py
File metadata and controls
32 lines (27 loc) · 943 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import argparse
import re
def main(img_dir: str) -> None:
"""
Remove "_XXXX" (where X is any digit) from the image file names.
This is necessary because of the file names resulting from
using Photoshop to export layers as files.
"""
for file_name in os.listdir(img_dir):
if not file_name.endswith(".jpg"):
continue
new_file_name = re.sub("_\d\d\d\d_", "_", file_name)
file_path = os.path.join(img_dir, file_name)
new_file_path = os.path.join(img_dir, new_file_name)
os.rename(file_path, new_file_path)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Pre-process images for the trajectory comparison matrix"
)
parser.add_argument(
"dir", help="path to directory of cropped named screenshots"
)
args = parser.parse_args()
main(args.dir)