milestone 3 - FileManager: has now the three functions list_files, read_file and save_file. switched os with pathlib

This commit is contained in:
Franziska Gerold 2026-05-23 17:09:57 +02:00
parent bf00e277c8
commit 7f63c8f2ae
3 changed files with 23 additions and 6 deletions

View File

@ -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
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"))

1
example.py Normal file
View File

@ -0,0 +1 @@
"blabliblu"

1
example_2.py Normal file
View File

@ -0,0 +1 @@
haHa