diff --git a/FileManager.py b/FileManager.py index 79e5f28..027d11d 100644 --- a/FileManager.py +++ b/FileManager.py @@ -1,14 +1,29 @@ +import os +from pathlib import Path -def list_files(): +def list_files() -> list: #soll Zugriff auf project directory haben und diese anzeigen - pass + #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): +def read_file(file_path: Path) -> str : #wenn eine Datei im Sidebar angeklickt wird, soll die Funktion sie lesen und im Code Editor anzeigen - pass + #file = open(file_path, 'r').read() + with file_path.open("r") as file: + return file.read() -def save_file(file_path, content): +def save_file(file_path: Path, content: str): #wenn eine Datei im Code Editor abgeändert wird, soll die Funktion die Änderungen abspeichern - pass \ No newline at end of file + 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")) \ No newline at end of file diff --git a/example.py b/example.py new file mode 100644 index 0000000..a1a88c4 --- /dev/null +++ b/example.py @@ -0,0 +1 @@ +"blabliblu" \ No newline at end of file diff --git a/example_2.py b/example_2.py new file mode 100644 index 0000000..3cf5bb7 --- /dev/null +++ b/example_2.py @@ -0,0 +1 @@ +haHa \ No newline at end of file