跟着 source insight 官网文档写了一个打开目录的宏,遇到一个奇怪的问题,不知是不是一个bug 呢?宏的实现如下:
macro OpenCurrentFileDir()
{
hbuf = GetCurrentBuf()
//这个是带绝对路径的文件名
bufFileName = GetBufName(hbuf)
nameLen = strlen(bufFileName)
ich = 0
chPos = nameLen
while(chPos > 0)
{
ch = bufFileName[chPos - 1]
//取文件名,不要路径,从末尾开始找第一个 "\", 这样就知道文件名的起点了
if(AsciiFromChar(ch) == 92)
{
break
}
chPos = chPos - 1
}
//以下是取文件所在的目录
filePath = Nil
i = 0
while(i < chPos)
{
ch = bufFileName[i]
if(ch == 92)
{
Msg(ch)
ch = 47 //转换了“/”
}
filePath = cat(filePath, ch)
i = i + 1
}
ret = ShellExecute("open", "C:\documents", Nil, Nil, 1)
Msg(ret)
//ShellExecute("open", "@filePath@", Nil, Nil, 1)
}
一开始跟着例子写了这个 ShellExecute("open", "C:\documents", Nil, Nil, 1) 是可以正常打开目录的
这个函数执行结果是非0,即为成功的,打开了如下的目录:
但是当我想要打开更深层的目录时,却始终的失败的 ret = ShellExecute("open", "C:\documents\case", Nil, Nil, 1)
为什么多加了一层目录就失败了呢?而且一直坚信这是在Windows下的啊,不可能用 Linux 的 "/" 啊,但出乎意料的是,在多层目录时它确实是用 "/" 才能执行成功。如上面的宏实现,将路径中的 "\" 转换为 "/" 后,执行 ShellExecute("open", "@filePath@", Nil, Nil, 1) 就能成功打开指定目录了:
这是为什么呢?搞不懂,这个函数跟 windows 下的 API HINSTANCE ShellExecuteA( [in, optional] HWND hwnd, [in, optional] LPCSTR lpOperation, [in] LPCSTR lpFile, [in, optional] LPCSTR lpParameters, [in, optional] LPCSTR lpDirectory, [in] INT nShowCmd ); 应该是相似的,它比这个函数少了第一个参数 hwnd 而已,所以有 windows 下开发的同学知道这是什么原因吗?