forked from twruetz/SortJPGRAW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteRAWWithoutJPG.py
61 lines (48 loc) · 1.98 KB
/
deleteRAWWithoutJPG.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
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 2 10:47:46 2019
Skript to delete/sort RAW Files not having a specific JPG patner
So you only delete the jpg, and the specific raw files get deleted,too
@author: Tim Wruetz
"""
import tkinter
from tkinter import filedialog
import os
import shutil
def main():
#Create and Hide window for directory search
root = tkinter.Tk()
root.withdraw()
#Set current directory as start point
currdir = os.getcwd()
#Select the directory, which should be cleaned
tempdir = filedialog.askdirectory(parent=root, initialdir=currdir, title='Please select a directory')
destination_folder = tempdir+"/delDir"
#Try to create a directory named delDir which contains raws without a jpg
#partner after script execution.
try:
os.mkdir(destination_folder)
print("Directory " , destination_folder , " Created ")
except FileExistsError:
print("Directory " , destination_folder , " already exists")
#If directory creation was successfull sort by jpg and orf
if len(tempdir) > 0:
path = tempdir
JPGfiles = []
RAWfiles = []
files = os.listdir(path)
for ii in range(len(files)):
if ".JPG" in files[ii]:
JPGfiles.append(files[ii].split(".")[0])
if ".jpg" in files[ii]:
JPGfiles.append(files[ii].split(".")[0])
if ".ORF" in files[ii]:
RAWfiles.append(files[ii].split(".")[0])
if ".orf" in files[ii]:
RAWfiles.append(files[ii].split(".")[0])
#Move Raws without jpg partner
for kk in range(len(RAWfiles)):
if not RAWfiles[kk] in JPGfiles:
shutil.move(tempdir+"/"+RAWfiles[kk]+".ORF", destination_folder+"/"+RAWfiles[kk]+".ORF")
if __name__ == "__main__":
main()