简体   繁体   English

Clean3.0获取目录内容

[英]Clean3.0 get directory contents

I am using Cleanide for Clean3.0 programming language. 我正在使用Cleanide for Clean3.0编程语言。 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... 我不知道这种功能的定义是否需要像File -> [string]或其他内容,即使该目录是一个文件,也可能不是Clean的开发者的意思。

Thank a lot! 非常感谢!

This functionality is not available in the StdEnv environment, but there are two libraries that can help with this: 此功能在StdEnv环境中不可用,但是有两个库可以帮助解决此问题:

  • 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 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) . 平台库包含一个模块System.Directory ,该模块具有函数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 ). 在这两种情况下,第一个参数是目录的路径,第二个参数是*World ,这是Clean执行不纯操作的典型方式(请参阅语言报告的 第9章 )。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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