-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_spotlight_rename_and_arrange.py
84 lines (73 loc) · 2.76 KB
/
copy_spotlight_rename_and_arrange.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# batch_add_file_extension.py
import os
import shutil
from PIL import Image
def main():
copy_spotlight_files()
add_img_ext()
sort_images()
def add_img_ext():
root = os.getcwd()
for file in os.listdir('.'):
if not os.path.isfile(file):
continue
# get the file name and extenstion
name, ext = os.path.splitext(file)
# print(name, ext)
if not ext:
src = os.path.join(root, file)
dst = os.path.join(root, file + '.jpg')
if not os.path.exists(dst):
os.rename(src, dst)
else:
os.remove(src)
# ADD The Ability to Move portrait images to the portraits folder
def sort_images():
root = os.getcwd()
if root[-1] != '/':
root = root + '/'
# Create the portrait directory
portrait_dir = root + "/portrait"
landscape_dir = root + "/landscape"
if not os.path.exists(portrait_dir):
os.makedirs(portrait_dir)
if not os.path.exists(landscape_dir):
os.makedirs(landscape_dir)
for file in os.listdir("."):
if not os.path.isfile(file):
continue
image_path = root + file
name, ext = os.path.splitext(file)
if ext in [".jpg", "jpeg", "png"]:
with Image.open(image_path) as image:
width, height = image.size
# print(width, height)
if width < height:
# move portrait image to portrait folder
try:
shutil.move(image_path, portrait_dir)
print(f"Moved {image_path} --> {portrait_dir}")
except:
print(f"Error moving {image_path}")
os.remove(image_path)
pass
else:
# landscape: move to landscape folder
try:
shutil.move(image_path, landscape_dir)
print(f"Moved {image_path} --> {landscape_dir}")
except:
print(f"Error moving {image_path}")
os.remove(image_path)
pass
# Copies microsoft spolight images
def copy_spotlight_files():
# shutil.copytree("C:\\Users\\Benfr\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets", os.getcwd())
# src = "C:\\Users\\Benfr\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets"
src = f"{os.environ['USERPROFILE']}\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets"
trg = os.getcwd()
files = os.listdir(src)
for file in files:
shutil.copy2(os.path.join(src,file), trg)
if __name__ == "__main__":
main()