29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
def list_files() -> list:
|
|
#soll Zugriff auf project directory haben und diese anzeigen
|
|
#mypath = "C:/FH_Graubünden/26FS/AI_in_SE/project_ai_se"
|
|
#files = [f for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]
|
|
mypath = Path.cwd()
|
|
print(f"u ä {mypath}")
|
|
files = list(mypath.glob('*.py'))
|
|
return files
|
|
|
|
def read_file(file_path: Path) -> str :
|
|
#wenn eine Datei im Sidebar angeklickt wird, soll die Funktion sie lesen und im Code Editor anzeigen
|
|
#file = open(file_path, 'r').read()
|
|
with file_path.open("r") as file:
|
|
return file.read()
|
|
|
|
def save_file(file_path: Path, content: str):
|
|
#wenn eine Datei im Code Editor abgeändert wird, soll die Funktion die Änderungen abspeichern
|
|
with file_path.open('w') as f:
|
|
f.write(content)
|
|
|
|
|
|
print(list_files())
|
|
print(read_file(Path("C:/FH_Graubünden/26FS/AI_in_SE/project_ai_se/pages/example.py")))
|
|
print(save_file(Path("C:/FH_Graubünden/26FS/AI_in_SE/project_ai_se/pages/example_2.py"), "haHa")) |