-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfile_manager.py
More file actions
49 lines (37 loc) · 1.58 KB
/
file_manager.py
File metadata and controls
49 lines (37 loc) · 1.58 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
import os
import shutil
from time import sleep
from datetime import datetime
"""
Moves all files created by Fluent session into folder in Logs directory
"""
# List of all files and folders that are off limits
static_files = ['.git', 'file_manager.py', 'inputs.csv', 'Logs', 'main.py', 'PyFluent', 'README.md',
'requirements.txt', '__pycache__', 'process.py', 'outputs.csv', 'venv', '.idea']
def organize_files(folder_name, mesh_name):
# create folder to store all info relating to mesh
os.mkdir(f'./Logs/{folder_name}/{mesh_name}')
# move all files not in static_files into the new directory
for file in os.listdir():
if file not in static_files:
try:
os.rename(f'./{file}', f'./Logs/{folder_name}/{mesh_name}/{file}')
except PermissionError:
try:
# incase Fluent is still shutting down and a file is being used
sleep(10)
os.rename(f'./{file}', f'./Logs/{folder_name}/{mesh_name}/{file}')
except PermissionError as e:
print(e)
# creates a new folder to hold all output data in log file
def new_log_folder():
# folder name is timestamp it is created in
folder_name = str(datetime.now())[:-7].replace(':', '-')
# create folder inside Logs
try:
os.mkdir(f'./Logs/{folder_name}')
except FileExistsError:
# if directory already exists, overwrite
for file in os.listdir(f'./Logs/{folder_name}'):
os.remove(f'./Logs/{folder_name}/{file}')
return folder_name