-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileOperations.py
More file actions
108 lines (73 loc) · 2.08 KB
/
fileOperations.py
File metadata and controls
108 lines (73 loc) · 2.08 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import time
import cv2
import numpy
from send2trash import send2trash
from tqdm import tqdm
def indexFiles(path):
imagePaths = []
subFolders = os.listdir(path+"/DCIM")
try:
subFolders.remove(".DS_Store") #for macOS
except:
pass
rawWarned = False
for folder in range(len(subFolders)):
workingDirectory = subFolders[folder]
imagePath = os.listdir(path+"/DCIM/"+workingDirectory+"")
try:
imagePath.remove(".DS_Store")
except:
pass
for picture in range(len(imagePath)):
if ((imagePath[picture])[-4:] == ".CR2") and not rawWarned:
warnAboutRAW()
rawWarned = True
if (imagePath[picture])[-4:] == ".JPG" or (imagePath[picture])[-4:] == ".jpg":
imagePaths.append(path+"/DCIM/"+workingDirectory+"/"+imagePath[picture])
else:
pass
return imagePaths
def warnAboutRAW():
print("\n")
print("\n")
print("\n")
print("*****************")
print("Warning! RAW files have been found on the selected SD card. The program currently does not support checking RAW files.")
print("If a JPEG is flagged for removal then the RAW files associated with it will be removed as well.")
print("A future release will scan RAW files as well, but for the time being please shoot in JPEG+RAW mode on the camera.")
print("*****************")
print("\n")
print("\n")
print("\n")
time.sleep(10)
def omitFileExtensions(pathArray):
imageCount = 0
for path in pathArray:
if(path[-4:] == ".JPG" or path[-4:] == ".jpg"):
imageCount += 1
if(path[-4:] != ".JPG" and path[-4:] != ".jpg"):
#ignore non jpeg files
pathArray.remove(path)
return pathArray
def getNumberOfFiles(filesArray):
return len(filesArray)
def purgePhotos():
f = open("CANON_DC.log", "r")
todel = f.read()
imagesToDelete = todel.splitlines()
print("Deleting flagged pictures...")
time.sleep(1)
for image in tqdm(imagesToDelete):
send2trash(image)
time.sleep(2)
print("\n")
print("\n")
print("Checking for RAW files and deleting them...")
for raw in tqdm(imagesToDelete):
try:
send2trash(raw[:len(raw)-4]+".CR2")
except:
pass
time.sleep(2)
f.close()