Hi All ,
I am using a function (found in the http://code.kx.com/wsvn/code/contrib/fdsupport/database%20maintenance/dbmaint.q) to convert a folder path in kdb to a path that can be used in windows (i.e. convert / to ) however it doesn’t appear to work as expected.
The function is pth
\d .os
WIN:.z.o inw32w64
pth:{p:$[10h=type x;x;string x];if[WIN;p[where"/“=p]:”\“];(”:"=first p)_ p}
\d .
When I try to run the function in a windows platform (i.e. WIN = true), “/” are replaced by “\” i.e.when I call the function I get the following
os.pth `:c:/temp/test1.txt
“c:\temp\test1.txt”
Has anyone got any suggestions?
Many thanks
David
I made a mistake in the original post - the pth function actually returns
“c:\temp\test1.txt”
On Wednesday, 23 October 2013 08:14:19 UTC+1, David Bieber wrote:
Hi All ,
I am using a function (found in the http://code.kx.com/wsvn/code/contrib/fdsupport/database%20maintenance/dbmaint.q) to convert a folder path in kdb to a path that can be used in windows (i.e. convert / to ) however it doesn’t appear to work as expected.
The function is pth
\d .os
WIN:.z.o inw32w64
pth:{p:$[10h=type x;x;string x];if[WIN;p[where"/“=p]:”\“];(”:"=first p)_ p}
\d .
When I try to run the function in a windows platform (i.e. WIN = true), “/” are replaced by “\” i.e.when I call the function I get the following
os.pth `:c:/temp/test1.txt
“c:\temp\test1.txt”
Has anyone got any suggestions?
Many thanks
David
You are just on / away.
Your original path should be `:c://temp/test1.txt. Does it make a difference?
.Q.s1 os.pth `:c//temp/test1.txt
Thanks Bartosz for you suggestion but it still doesn’t work..
… In fact if I use `:c://temp/test1.txt kdb returns
c\\temp\test1.txt
i.e. it is replacing / with \
David
I’ts the way strings work. First \ is escaping the second one:
http://code.kx.com/wiki/Reference/BackSlash#escape
Hi Bartosz,
I am confused, I still can’t figure out why this function is not working. The code uses “\” (i.e. escape and )
if[WIN;p[where"/“=p]:”\"]
but when I run the code it for some reason replaces it with a \. Odd.
Any ideas?
Regards
David
What do you see in console?
Is it “c:\\temp\test1.txt”? add show to your result and check what’s in the console.
Br,
B
stringify will add escapes during printing.
look at the raw char count.
e.g.
q)count 0N!“hello/world/goodbye”
“hello/world/goodbye”
19
q)count 0N!{x[where"/“=x]:”\";x}“hello/world/goodbye”
“hello\world\goodbye”
19
Thanks Charles,
Well that make more sense - I was receiving an error and thought that the it was caused by the \. In fact there is an error in the syntax of the ren function in http://code.kx.com/wsvn/code/contrib/fdsupport/database%20maintenance/dbmaint.q.
In line 7 "ren " should be replaced by "move "
ren:{system$[WIN; "move " ;"mv “],pth,” ",pth y}
Not sure if there is a way to submit a revision…
Kind regards
David
On Wednesday, 23 October 2013 11:11:22 UTC+1, Charles Skelton wrote:
stringify will add escapes during printing.
look at the raw char count.
e.g.
q)count 0N!“hello/world/goodbye”
“hello/world/goodbye”
19
q)count 0N!{x[where"/“=x]:”\“;x}”hello/world/goodbye"
“hello\world\goodbye”
19