Directory Rebol2:将目录更改为绝对文件路径不工作

Directory Rebol2:将目录更改为绝对文件路径不工作,directory,filepath,absolute,rebol,rebol2,Directory,Filepath,Absolute,Rebol,Rebol2,我试图从配置文件中读取文件路径,然后从该目录中读取。不过,我找不到一种方法使其工作,因为出于某种原因,change dir从不使用绝对文件路径。这是我试图让它在CLI上工作的记录 >> test: pick read/lines %test.ini 1 == "test: C/Users/thompson/Downloads/" >> test: find test " " == " C/Users/thompson/Downloads/" >> test:

我试图从配置文件中读取文件路径,然后从该目录中读取。不过,我找不到一种方法使其工作,因为出于某种原因,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

找到了一个有效的解决方法

changeDirAbsolute: func [input] [
change-dir %/
change-dir input
]

如果有人有更优雅的解决方案,我愿意听

在Rebol中,因为代码是数据,数据是代码,所以可以用Rebol代码表示.ini文件。顺便说一句,我和其他许多不以Windows为中心的人更喜欢使用.cfg作为这些类型文件的扩展名。ini指的是“初始化”,在许多人看来,它指的是系统的启动,但也可能指的是程序的启动。cfg更精确一点,因为它是程序的配置文件

话虽如此,请尝试以下方法:

test.cfg:

test: %/c/users/thompson/downloads
然后,您只需在程序中执行以下操作:

>> do %test.cfg
这将自动将文件路径填充到单词“test”中

在非基于Windows的操作系统中,当文件路径指向文件系统的根级别时,通常以/开头。如果它不是以/开头,那么它是一个相对路径(从当前目录开始)


我希望这有帮助

它失败了,因为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

有很多方法可以获得绝对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:"
窗道

test: "test: C:/Users/thompson/Downloads/"
to-rebol-file trim find/tail test "test:"
您将始终获得
%/C/Users/thompson/Downloads/