importPour l'utiliser : import System.File
System.File — lecture et écriture de fichiers entiers
Synopsis
data FileError
= NotFound Path
| PermissionDenied Path
| AlreadyExists Path
| NotAFile Path
| IOError String
fichier attendu, autre chose trouvé
NotFound
fichier attendu, autre chose trouvé
PermissionDenied
fichier attendu, autre chose trouvé
AlreadyExists
fichier attendu, autre chose trouvé
NotAFile
fichier attendu, autre chose trouvé
IOError
toute autre erreur, avec un message
ioError : String -> FileError
Une simple erreur IO issue d'un message (sans chemin), pour les opérations fondées sur un handle.
classify : Path -> String -> FileError
readFile : Path -> Result FileError String with FileRead
Lit un fichier entier sous forme de chaîne. readFile (path "notes.txt") vaut Ok "<contents>", ou Error (NotFound …).
writeFile : Path -> String -> Result FileError () with FileWrite
Écrit une chaîne dans un fichier, en remplaçant tout contenu existant.
appendFile : Path -> String -> Result FileError () with FileWrite
Ajoute une chaîne à la fin d'un fichier (en le créant si nécessaire).
exists : Path -> Bool with FileRead
isFile : Path -> Bool with FileRead
Ce chemin existe-t-il et est-ce un fichier ordinaire ?
isDir : Path -> Bool with FileRead
Ce chemin existe-t-il et est-ce un répertoire ?
fileSize : Path -> Result FileError Nat with FileRead
La taille d'un fichier en octets.
readLines : Path -> Result FileError (List String) with FileRead
Lit un fichier et le découpe en lignes.
writeLines : Path -> List String -> Result FileError () with FileWrite
Écrit une liste de lignes dans un fichier, une par ligne (chacune suivie d'un saut de ligne).
readFileOr : String -> Path -> String with FileRead
Lit un fichier, avec repli sur une chaîne par défaut s'il ne peut pas être lu. Une commodité pour quand on ne veut pas gérer l'erreur explicitement.