clean-language

Clean3.0 get directory contents


I am using Cleanide for Clean3.0 programming language. What I am trying to do is to implement a function that receive name of a directory in my system, and return a list of all the files in that directory.

I don't know if the defintion of such function needs to be like File -> [string] or maybe something else, even that directory is a file maybe this is not the developers of Clean meant...

Thank a lot!


Solution

  • This functionality is not available in the StdEnv environment, but there are two libraries that can help with this:

    In both cases the first argument is a path to the directory and the second argument is the *World, which is the typical way of Clean to perform impure operations (see chapter 9 of the language report).

    Code examples

    With Directory:

    import Directory
    
    Start w
    # (dir,w) = getDirectoryContents (RelativePath []) w
    = dir
    

    With Platform:

    import System.Directory
    
    Start w
    # (dir,w) = readDirectory "." w
    = dir