Run a script in the same directory as the current script

Since $0 holds the full path of the script that is running, you can use dirname against it to get the path of the script: #!/bin/bash script_name=$0 script_full_path=$(dirname “$0”) echo “script_name: $script_name” echo “full path: $script_full_path” so if you for example store it in /tmp/a.sh then you will see an output like: $ /tmp/a.sh script_name: … Read more

What does \\?\ mean when prepended to a file path

A long read, but worth reading if you are in this domain: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx Extract: The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value … Read more

How can I open files relative to my GOPATH?

Hmm… the path/filepath package has Abs() which does what I need (so far) though it’s a bit inconvenient: absPath, _ := filepath.Abs(“../mypackage/data/file.txt”) Then I use absPath to load the file and it works fine. Note that, in my case, the data files are in a package separate from the main package from which I’m running … Read more

Node npm windows file paths are too long to install packages

The problem with deeply nested folders on Windows has been mostly solved starting with npm version 3.x. According to npm: .npm@3 makes the install “maximally flat” by hoisting everything it can to the top level node_modules. This means nesting only occurs on conflicts and as such, trees should never get very deep. As such, the … Read more

Directory.GetFiles: how to get only filename, not full path? [duplicate]

You can use System.IO.Path.GetFileName to do this. E.g., string[] files = Directory.GetFiles(dir); foreach(string file in files) Console.WriteLine(Path.GetFileName(file)); While you could use FileInfo, it is much more heavyweight than the approach you are already using (just retrieving file paths). So I would suggest you stick with GetFiles unless you need the additional functionality of the FileInfo … Read more

How to build a full path string (safely) from separate strings?

Only as part of Boost.Filesystem library. Here is an example: #include <iostream> #include <boost/filesystem.hpp> namespace fs = boost::filesystem; int main () { fs::path dir (“/tmp”); fs::path file (“foo.txt”); fs::path full_path = dir / file; std::cout << full_path << std::endl; return 0; } Here is an example of compiling and running (platform specific): $ g++ ./test.cpp … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)