Loading src/common/file_operations.py +10 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,13 @@ def delete_directory(dirc=None): if dirc is not None: try: if path_exists(dirc): Path(dirc).rmdir() directory_to_delete = Path(dirc) for item in directory_to_delete.iterdir(): if item.is_file(): item.unlink() if item.is_dir(): item.rmdir() directory_to_delete.rmdir() return f"{dirc} deleted successfully." else: return f"{dirc} does not exist." Loading Loading @@ -125,6 +131,9 @@ def write_file(file_name, file_data=""): """ try: if Path(file_name).suffix == ".json": if not Path(file_name).exists(): with open(f"{file_name}", 'w') as json_file: json_file.write(json.dumps({})) with open(f"{file_name}", "r+") as file: file_contents = json.load(file) file_contents.update(file_data) Loading Loading
src/common/file_operations.py +10 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,13 @@ def delete_directory(dirc=None): if dirc is not None: try: if path_exists(dirc): Path(dirc).rmdir() directory_to_delete = Path(dirc) for item in directory_to_delete.iterdir(): if item.is_file(): item.unlink() if item.is_dir(): item.rmdir() directory_to_delete.rmdir() return f"{dirc} deleted successfully." else: return f"{dirc} does not exist." Loading Loading @@ -125,6 +131,9 @@ def write_file(file_name, file_data=""): """ try: if Path(file_name).suffix == ".json": if not Path(file_name).exists(): with open(f"{file_name}", 'w') as json_file: json_file.write(json.dumps({})) with open(f"{file_name}", "r+") as file: file_contents = json.load(file) file_contents.update(file_data) Loading