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!
Related
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?
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
Ok so with siriproxy it my lib folder along with the rb file for the plugin I have created a myconfig.yml file so I can change certain settings by writing to that file.
I have been able to write to the file but only if I include the full path all the way from the home directory down.
But is there not a way to open the file from the same directory i am in? I have tried every path combination I can think of.
There has to be one i am missing
If you use the following in your ruby file, you should get the absolute path where it is
File.expand_path(__FILE__)
From doc __FILE__
The name of the file currently being executed, including path relative to the directory where the application was started up (or the current directory, if it has been changed)
From doc File.expand_path
Converts a pathname to an absolute pathname.
As you probably want the directory, you should use File.dirname(__FILE__), so the path of your file myconfig.yml should be obtained with
File.join(File.expand_path(File.dirname(__FILE__)), 'myconfig.yml')
In more recent Ruby (>=2.0.0), you can use __dir__ (from Archonic's comment):
Returns the canonicalized absolute path of the directory of the file from which this method is called. It means symlinks in the path is resolved. If FILE is nil, it returns nil. The return value equals to File.dirname(File.realpath(FILE)).
I have a JAR with a bunch of configs. I'd like to send them to the correct directory without cd'ing there.
Something like jar xf config.jar --MAGIC-PARAM PATH/TO/DIRECTORY
Is there such a thing? If it helps, this will be called by a Buildr extension (Ruby).
From the API documentation: http://buildr.apache.org/rdoc/classes/Buildr/Unzip.html
unzip(dir => zip_file).target.invoke
Alex's answer is good. If there's some special magic that jar xf does that makes you prefer it to unzipping (I'm not aware of any), here's another option:
FileUtils.cd('PATH/TO/DIRECTORY') do
system("jar xf '#{_('config.jar')'")
end
It does involve cd'ing, but when you use cd with a block, the original directory is restored after the block. You will need to use either an absolute path or a path relative to the directory you changed to; I'm using buildr's _ method to get an absolute path for a project-relative file.
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";
?>