-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.py
More file actions
42 lines (35 loc) · 1.03 KB
/
helper.py
File metadata and controls
42 lines (35 loc) · 1.03 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
import os
def getFilesRecursively(directory, extension=".JPG"):
ret = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(extension):
ret.append(os.path.join(root, file))
return ret
def getBaseNames(paths):
ret = []
for path in paths:
ret.append(os.path.basename(path))
return ret
def getBaseName(path):
return os.path.basename(path)
def getPathForName(name, paths):
for path in paths:
if os.path.basename(path) == name or os.path.splitext(os.path.basename(path))[0] == name:
return path
return None
def dropExtension(files):
ret = []
for file in files:
ret.append(os.path.splitext(file)[0])
return ret
def dropExtension_file(file):
return os.path.splitext(file)[0]
def addExtensionToFiles(files, extension):
ret = []
for file in files:
if "." in extension:
ret.append(f"{file}{extension}")
else:
ret.append(f"{file}.{extension}")
return ret