-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (22 loc) · 802 Bytes
/
utils.py
File metadata and controls
28 lines (22 loc) · 802 Bytes
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
import os
import shutil
def create_folder(path_out, purge=False):
""" Creates output folder (path_out) if it does not exist. """
path_out = path_out.replace('\\', '/')
folders = path_out.split('/')
# create all necessary folders on the path
for i, folder in enumerate(folders):
if folder != '..':
path = os.path.join(*folders[0:i+1])
if not os.path.exists(path):
os.mkdir(path)
if purge:
shutil.rmtree(path_out)
os.mkdir(path_out)
def get_file_list(path_folder, extension=''):
""" Lists all files from a folder with an specific file extension. """
files = []
for file_name in os.listdir(path_folder):
if file_name.endswith(extension):
files.append(file_name)
return files