file_manager.py•603 B
import os
def create_folder(path: str):
os.makedirs(path, exist_ok=True)
def create_py_file(path: str, content: str = ""):
if not path.endswith(".py"):
raise ValueError("File must have a .py extension")
folder = os.path.dirname(path)
if folder:
os.makedirs(folder, exist_ok=True)
with open(path, "w", encoding="utf-8") as f:
f.write(content)
def edit_file_content(path: str, content: str):
if not os.path.exists(path):
raise FileNotFoundError(f"File not found: {path}")
with open(path, "w", encoding="utf-8") as f:
f.write(content)