Verified Commit 0b75f055 authored by Camil Staps's avatar Camil Staps 🚀

Add platform-independent scanDirectory function

parent d5a364e9
Pipeline #13713 passed with stage
in 56 seconds
definition module System.Directory
from System.File import :: FileInfo
import System._Directory
/**
* Recursively scan a directory and collect information about all files and
* directories it contains.
*
* @param A function that is used to update a state (`st`) for every file or
* directory encountered. A directory is given before everything it contains.
* Otherwise, no guarantees w.r.t. order are made.
* @param The initial state.
* @param The directory to scan. The update function is also called with this
* directory as an argument.
* @param The world.
* @result All errors encountered.
* @result The updated state.
* @result The new world.
*/
scanDirectory :: !(FilePath FileInfo .st *World -> *(.st, *World)) !.st !FilePath !*World -> *(![OSError], !.st, !*World)
implementation module System.Directory
import StdBool
import StdClass
import StdString
import Data.Error
from Data.Func import $
import System._Directory
import System.File
import System.FilePath
scanDirectory :: !(FilePath FileInfo .st *World -> *(.st, *World)) !.st !FilePath !*World -> *(![OSError], !.st, !*World)
scanDirectory upd st dir w = scan dir [] st w
where
scan dir errs st w
# (fi,w) = getFileInfo dir w
# (errs,st,w) = case fi of
Error e -> ([e:errs], st, w)
Ok fi -> (\(st,w) -> (errs,st,w)) $ upd dir fi st w
| isError fi = (errs, st, w)
# fi = fromOk fi
| not fi.directory = (errs, st, w)
# (contents,w) = readDirectory dir w
| isError contents = ([fromError contents:errs], st, w)
# contents = [dir </> fp \\ fp <- fromOk contents | fp <> "." && fp <> ".."]
= seqSt3 scan contents errs st w
seqSt3 f [] s1 s2 s3 = (s1, s2, s3)
seqSt3 f [x:xs] s1 s2 s3
# (s1,s2,s3) = f x s1 s2 s3
= seqSt3 f xs s1 s2 s3
definition module System.Directory
definition module System._Directory
from System.FilePath import :: FilePath
from Data.Error import :: MaybeError
......
implementation module System.Directory
implementation module System._Directory
import StdArray, StdBool, StdClass, StdInt, StdChar, StdString
......
definition module System.Directory
definition module System._Directory
from System.FilePath import :: FilePath
from Data.Error import :: MaybeError
......
implementation module System.Directory
implementation module System._Directory
import StdArray, StdBool, StdClass, StdInt, StdChar, StdString
......
......@@ -143,6 +143,7 @@ import qualified System.Platform
import qualified System.Process
import qualified System.TTS
import qualified System.Time
import qualified System._Directory
import qualified System._FilePath
import qualified System._Platform
import qualified System._Pointer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment