forked from norkator/open-intelligence
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileutils.py
More file actions
72 lines (44 loc) · 1.66 KB
/
fileutils.py
File metadata and controls
72 lines (44 loc) · 1.66 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
import os
import os.path
import time
from pathlib import Path
# Variables
path = os.getcwd() + '/images/'
# -----------------------------------------
# Camera image processing
# def get_camera_image_path():
# return path
def get_camera_image_names(directory_path):
files = []
for file_name in os.listdir(directory_path):
p = os.path.join(directory_path, file_name)
if os.path.isdir(p):
continue
else:
files.append(file_name)
return files
def get_file_extension(root_path, directory_path, file_name):
filename, file_extension = os.path.splitext(root_path + directory_path + file_name)
return file_extension
def get_file_create_time(root_path, directory_path, file_name):
return time.gmtime(os.path.getmtime(root_path + directory_path + file_name))
def get_file_create_year(gm_time):
return time.strftime('%Y', gm_time)
def get_file_create_month(gm_time):
return time.strftime('%m', gm_time)
def get_file_create_day(gm_time):
return time.strftime('%d', gm_time)
def get_file_create_hour(gm_time, time_offset_hours=0):
hours = int(time.strftime('%H', gm_time)) + time_offset_hours
return str(hours)
def get_file_create_minute(gm_time):
return time.strftime('%M', gm_time)
def get_file_create_second(gm_time):
return time.strftime('%S', gm_time)
def get_file_mtime(root_path, directory_path, file_name):
return os.path.getmtime(root_path + directory_path + file_name)
# -----------------------------------------
# Directory tools
def create_directory(directory_path):
Path(directory_path).mkdir(parents=True, exist_ok=True)
# -----------------------------------------