我正在尝试从配置文件中读取文件路径,然后从该目录中读取。我找不到一种方法来让它工作,因为出于某种原因,change-dir从来不会进入绝对的文件路径。这是我试图让它在CLI上工作的文字记录。
>> test: pick read/lines %test.ini 1
== "test: C/Users/thompson/Downloads/"
>> test: find test " "
== " C/Users/thompson/Downloads/"
>> test: next test
== "C/Users/thompson/Downloads/"
>> test: to file! test
== %C/Users/thompson/Downloads/
>> change-dir test
** Access Error: Cannot open /C/rscratch/C/Users/thompson/Downloads/
** Near: change-dir test发布于 2016-10-25 11:54:58
它失败了,因为Rebol没有看到
%C/Users/thompson/Downloads/作为绝对路径-它缺少魔术前导斜杠,因此被视为相对路径。绝对路径是这样的:
%/C/Users/thompson/Downloads/因此,如果您确定没有前导斜杠,那么很容易修复:
>> test: pick read/lines %test.ini 1
== "test: C/Users/thompson/Downloads/"
>> test: find test " "
== " C/Users/thompson/Downloads/"
>> test: next test
== "C/Users/thompson/Downloads/"
>> test: to file! join "/" test发布于 2016-10-25 13:54:17
有很多方法可以得到一个绝对的Rebol文件路径,
Rebol方式
test: "test: %/C/Users/thompson/Downloads/"
select load test [test:]linux方式
test: "test: /C/Users/thompson/Downloads/"
to-file trim find/tail test "test:"Windows方式
test: "test: C:/Users/thompson/Downloads/"
to-rebol-file trim find/tail test "test:"您将始终获得%/C/Users/thompson/Downloads/
发布于 2016-10-25 02:27:34
找到了一种有效的解决方法。
changeDirAbsolute: func [input] [
change-dir %/
change-dir input
]如果有人有更好的解决方案,我很乐意听听!
https://stackoverflow.com/questions/40223462
复制相似问题