简体   繁体   中英

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!

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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM