Clean3.0 get directory contents

54 views Asked by At

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!

1

There are 1 answers

4
AudioBubble On BEST ANSWER

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

  • The Directory library contains a module Directory which has a function getDirectoryContents :: !Path !*env -> (!(!DirError, [DirEntry]), !*env) | FileSystem env.

  • The Platform library contains a module System.Directory which has a function readDirectory :: !FilePath !*w -> (!MaybeOSError [FilePath], !*w).

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