KDB:如何将相对路径转换为绝对路径?

KDB: How to convert relative path to absolute path?

KDB中有没有办法将相对路径转换为绝对路径?

例如:

filePath: `$concat[localPath,"\",inProcessID,"\",filename]

哪个returns:

`..\..\code\products\Q\ShortLocator2\Request Files\Locate_CCL_11-13-2018_074736.csv

然后现在我想将其转换为绝对路径。

您可以输入当前工作目录...

q)homepath:`$system"pwd" // for Linux ,`/home/user q)homepath:`$system"cd" // for Windows ,`C:\Users\user

要获取绝对路径,请执行...

q).Q.dd[hsym homepath; filepath] `:/home/user/.. 这应该是 return 绝对路径。

这是否回答了您的问题?

您需要文件的规范路径吗?如果您在 linux 上,阅读链接通常可用并且可能有帮助:

system "readlink -f ", filepath

但这显然对 Windows 没有帮助(您似乎正在使用它?)。我不知道有类似的工具。

最终你应该解决为什么你的 "localPath" 变量是相对的问题,但这里有一个丑陋的函数来解决你的问题:

q){hsym `$("\" sv neg[c]_"\" vs system"cd"),"\","\" sv (c:count where ".."~/:a)_a:"\" vs string x}[filePath]
`:C:\Users\code\products\Q\ShortLocator2\Request Files\Locate_CCL_11-13-201..

具体到windows