gpt4 book ai didi

directory - 如何使用纯 Red 语言存储目录文件列表?

转载 作者:行者123 更新时间:2023-12-02 22:18:04 24 4
gpt4 key购买 nike

我正在尝试将目录中的文件列表存储在变量中(仅使用 CLI,红色版本:0.6.3)。

我测试了 "Red by example" 中的几个函数文档,但所有这些都只给我一个 CLI 输出,其中包含目录中的元素列表:

当我尝试将其保存到变量中时,出现如下错误:

>> var: list-dir %tests
other-tests.red README.md poc-tests.red
*** Script Error: var: needs a value
*** Where: var
*** Stack:

>> files: ls tests
other-tests.red README.md poc-tests.red
*** Script Error: files: needs a value
*** Where: files
*** Stack:

>> other: dir %tests
other-tests.red README.md poc-tests.red
*** Script Error: other: needs a value
*** Where: other
*** Stack:

我还找到了call方法,它使我可以运行外部脚本(如 shell 脚本),这样我就可以执行操作系统命令 ls:

>> filelist: ""
>> call/output "ls tests" filelist
>> print filelist
other-tests.red
poc-tests.red
README.md

但是这个解决方案依赖于操作系统。例如,在 MS Windows 中调用/输出“目录测试”文件列表将起作用。

谁能告诉我 - 是否有另一种解决方案可以使用纯红色代码而不执行外部脚本?

也许在某个地方有一些来自红色系统神奇功能,谁能给我们这些?

如果能够独立于操作系统那就太好了。

谢谢各位的解答

最佳答案

所需要的只是读取目录:

read %tests/

这将为您提供一个文件 block !目录内容的值。

关于directory - 如何使用纯 Red 语言存储目录文件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48776999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com