-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera_sort.py
executable file
·39 lines (29 loc) · 969 Bytes
/
camera_sort.py
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
39
#!/usr/bin/env python3.5
import os
import progressbar
def create_dir(path):
try:
os.mkdir(path)
except FileExistsError:
pass
def move_file(src, dst):
try:
os.replace(src, dst)
except FileExistsError:
dst += '_copy'
move_file(src, dst)
if __name__ == '__main__':
src_dir = os.path.abspath(input("Enter source dir: "))
dst_dir = "/home/admin/Pictures/Camera unsorted test"
create_dir(dst_dir)
bar = progressbar.ProgressBar()
last_subdir = None
for entry in bar(os.listdir(src_dir)):
if entry.endswith('.jpg') or entry.endswith('.mp4'):
subdir = entry[0:4] + '.' + entry[4:6] + '.' + entry[6:8]
if subdir != last_subdir:
last_subdir = subdir
create_dir(os.path.join(dst_dir, subdir))
src = os.path.join(src_dir, entry)
dst = os.path.join(dst_dir, subdir, entry)
move_file(src, dst)