Skip to content

Commit

Permalink
Refactor file handling functions in helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Oct 15, 2024
1 parent 58c4f53 commit 0c8b07c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import os


def create_directory(directory):
"""
Creates a directory if it doesn't exist.
"""
if not os.path.exists(directory):
os.makedirs(directory)


def read_file(file_path):
"""
Reads the contents of a file and returns them as a string.
"""
with open(file_path, 'r') as file:
with open(file_path, "r") as file:
return file.read()


def write_file(file_path, content):
"""
Writes the given content to a file.
"""
with open(file_path, 'w') as file:
with open(file_path, "w") as file:
file.write(content)


def delete_file(file_path):
"""
Deletes a file if it exists.
"""
if os.path.exists(file_path):
os.remove(file_path)
os.remove(file_path)

0 comments on commit 0c8b07c

Please sign in to comment.