Search code examples
formatrelative-pathkdb+absolute-path

KDB: How to convert relative path to absolute path?


Is there a way to convert a relative path to an absolute path in KDB?

For example:

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

Which returns:

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

And then now I want to convert this to absolute path.


Solution

  • Ultimately you should solve the problem of why your "localPath" variable is relative in the first place, but here is an ugly function to solve your problem:

    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\1\Locate_CCL_11-13-201..
    

    It is specific to windows