KDB: How to convert relative path to absolute path? - format

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.

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

Do you need the canonical path to the file? If you are on linux readlink is commonly available and may help:
system "readlink -f ", filepath
But this obviously doesn't help for Windows (which it looks like you are using?). I'm not aware of a similar tool.

You can get the current working directory by typing...
q)homepath:`$system"pwd" // for Linux
,`/home/user
q)homepath:`$system"cd" // for Windows
,`C:\\Users\\user
To get the absolute path do...
q).Q.dd[hsym homepath; filepath]
`:/home/user/..
This should return the absolute path.
Does that answer your question?

Related

How can I resolve a relative path to absolute path in golang?

Is there a api like 'path.resolve' in node? Or something can do the same?
For Example (nodejs code):
path.resolve("~/sample.sh")
Should got: /home/currentuser/sample.sh
Resolving ~ (denoting the user home) is a different story, and usually it's the shell that resolves this. For details see Expand tilde to home directory.
If you want to do it from Go code, you may use the user.Current() function to get details about the current user, including its home folder which will be User.HomeDir. But still, you'll have to handle replacing this yourself.
Original answer follows.
You may use path.Join() or filepath.Join().
For example:
base := "/home/bob"
fmt.Println(path.Join(base, "work/go", "src/github.com"))
Output:
/home/bob/work/go/src/github.com
You may use path.Clean() and filepath.Clean() to "remove" dots . and double dots .. from your path.
You may use filepath.Abs() to resolve relative paths and get an absolute (prepending the working directory if it's not absolute). filepath.Abs() also calls Clean() on the result.
For example:
fmt.Println(filepath.Abs("/home/bob/../alice"))
Outputs:
/home/alice <nil>
Try the examples on the Go Playground.
See related question: Resolving absolute path from relative path

nar-maven-plugin change output path

I am using nar-maven-plugin to build my c++ projects,everything is OK, the only problem is that the output is located at
..\target\nar\socketutility-1.0.0-SNAPSHOT-amd64-Windows-gpp-shared\lib\amd64-Windows-gpp\shared
This is a long path, I have two questions for this:
can this path be represented by one variable like ${project.xx}?
can I customize this path?

How to store file with an absolute path?

How can I store a file with the absolute path /var/www/cityscape/public/storage/img/newyork.jpg?
I tried Storage::put() (https://laravel.com/docs/5.3/filesystem#storing-files), but this method seems to only accept relative paths.
If the path you've specified in your question is in the same system as your app you can use File instead:
File::put('/var/www/cityscape/public/storage/img/newyork.jpg', $theFile);
Hope this helps!

How to print filename/current directory as a title in octave plot from bash?

I am new to octave and need to plot a 2-D graph with customized title either as a file name or current directory name. I tried passing pwd in the plot.m file but it gives me a complete path instead of directory name only. Actually all I need is a customized title without manually hard coding the string inside xlabel('strings').
I don't have Octave but this works on MATLAB:
current_directory_name = pwd;
current_directory_split = regexp(current_directory_name,'/','split');
string_of_interest = current_directory_split(end);
xlabel(string_of_interest);
I am assuming you are on *NIX computer. For Windows computer, change / to \ in the split command.
If I understood your question correctly, you want a portable way of retrieving the file name w/o the directory name. Use fileparts():
[dir, name, ext, ver] = fileparts(pwd)
If you later decide to join strings, use filesep which is portable no matter if you're on Unix or not.

Current path in PHP on Windows (standalone CLI)

I was trying to get path current path in PHP. I tried looking though phpinfo();, but I haven't found any interesting values which could be used to get path to my script. There is no nice values which I used on Linux, like $_SERVER["PWD"].
Now I'm wondering how I'm supposed to find current path. Maybe some function will work... I really have no idea. Because I don't want to hardcode path to script.
getcwd() is what you are looking for.
It's not entirely clear whether you mean the current working directory, or the path to the current script. For the working directory, see #Taze's answer.
For the current script, the __FILE__ magic constant will give you the full filesystem path to the current file.
Note that these constants take "current file" literally: If you include a file and call __FILE__ there, it will show the included file's path.
The getcwd() method will return the current working directory on success.
<?php
echo getcwd() . "\n";
?>

Resources