prolog - 如何在prolog中编写具有绝对路径的文件
问题描述
我当前的代码如下。如何为文件添加绝对路径或完整路径?我希望将文件保存在与当前工作目录不同的目录中。谢谢。
fileName('text.txt', Fname),
open(Fname, write, Stream1),
close(Stream1).
解决方案
只需使用带有/
分隔符的路径(即使在 Windows 上)
选项有点过火:
?- open("/tmp/myfile.txt",write,Stream,alias(my_sink),encoding(utf8),type(text)]),
write(Stream,foo(12,"Programmation en logique, très recommandée")),
close(Stream).
然后有一个新文件:
$ file /tmp/myfile.txt
/tmp/myfile.txt: UTF-8 Unicode text, with no line terminators
不确定如果您使用包含“保留字符”的路径会发生什么 - 其中一个是文件系统相关的。在 Windows 上有很多,在 Unix 文件系统上通常只有一个:/
. open/N
可能会抛出。
用于atomic_list_concat/3
构造路径:
?- atomic_list_concat([my,parent,dir],'/',Path).
Path = 'my/parent/dir'.
推荐阅读
- python - 是否可以修复 tfpl.IndependentNormal 中的均值/var arg?
- r - 从 R 中的位置字符串中查找城市、州和国家/地区信息
- python - RuntimeWarning:从未等待协程“current_time”返回浮点(anyio.current_time())
- flutter - 当我在颤振中使用带有本地小部件的final时,我应该添加类类型吗?
- swift - 测试使用 XCTest 传递给多个分析跟踪器的分析事件
- python - 如何避免 Django NoReverseMatch 错误?
- android - MPAndroidChart - 将 MarkerView 移动到条形图边界之外(不切断)
- javascript - 调用函数(需要参数)作为参数
- npm - 安装 npm 的问题 - 错误消息
- mysql - MySQL内部连接元字段类型结构