-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.py
29 lines (26 loc) · 895 Bytes
/
logic.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
# Here will be the underlying logic of the states
import os
import filetype
def buildDirStructure(start_dir):
tempNames = []
# I don't like try-except in production code, but os.listdir()
# will literally terminate the code if the user clicks on "cancel"
try:
tempNames = os.listdir(start_dir)
except:
return False
filesArray = []
for tempName in tempNames:
tempPath = os.path.join(start_dir, tempName).replace("\\", "/")
rawTempPath = r'{}'.format(tempPath)
if os.path.exists(rawTempPath) and os.path.isfile(rawTempPath):
if filetype.is_image(rawTempPath):
filesArray.append(rawTempPath)
else:
newArray = buildDirStructure(rawTempPath)
if newArray:
filesArray += newArray
if filesArray:
return filesArray
else:
return False