Completed
Pull Request — master (#32)
by Philip
01:30
created

ensure_file_directory()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
"""File system operations."""
2
3
import os
4
5
6
def file_exists(file_path):
7
    """Check if the full file path exists."""
8
9
    try:
10
        with open(file_path, 'r'):
11
            return True
12
    except IOError:
13
        raise FileExistsError
14
15
16
def ensure_directory(path: str):
17
    """Ensure that a directory path exists."""
18
19
    try:
20
        os.makedirs(path, exist_ok=False)
21
    except FileExistsError:
22
        pass
23
24
25
def ensure_file_directory(file_path: str):
26
    """Ensure that a directory path exists."""
27
28
    ensure_directory(os.path.dirname(file_path))
29