Get current folder path

You should not use Directory.GetCurrentDirectory() in your case, as the current directory may differ from the execution folder, especially when you execute the program through a shortcut. It’s better to use Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); for your purpose. This returns the pathname where the currently executing assembly resides. While my suggested approach allows you to differentiate between the … Read more

C# getting the path of %AppData%

To get the AppData directory, it’s best to use the GetFolderPath method: Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) (must add using System if not present). %AppData% is an environment variable, and they are not automatically expanded anywhere in .NET, although you can explicitly use the Environment.ExpandEnvironmentVariable method to do so. I would still strongly suggest that you use GetFolderPath however, … Read more

Draw path between two points using Google Maps Android API v2

First of all we will get source and destination points between which we have to draw route. Then we will pass these attribute to below function. public String makeURL (double sourcelat, double sourcelog, double destlat, double destlog ){ StringBuilder urlString = new StringBuilder(); urlString.append(“http://maps.googleapis.com/maps/api/directions/json”); urlString.append(“?origin=”);// from urlString.append(Double.toString(sourcelat)); urlString.append(“,”); urlString.append(Double.toString( sourcelog)); urlString.append(“&destination=”);// to urlString.append(Double.toString( destlat)); urlString.append(“,”); … Read more

How to construct a relative path in Java from two absolute paths (or URLs)?

It’s a little roundabout, but why not use URI? It has a relativize method which does all the necessary checks for you. String path = “/var/data/stuff/xyz.dat”; String base = “/var/data”; String relative = new File(base).toURI().relativize(new File(path).toURI()).getPath(); // relative == “stuff/xyz.dat” Please note that for file path there’s java.nio.file.Path#relativize since Java 1.7, as pointed out by … Read more

How do I find the location of the executable in C? [duplicate]

To summarize: On Unixes with /proc really straight and realiable way is to: readlink(“/proc/self/exe”, buf, bufsize) (Linux) readlink(“/proc/curproc/file”, buf, bufsize) (FreeBSD) readlink(“/proc/self/path/a.out”, buf, bufsize) (Solaris) On Unixes without /proc (i.e. if above fails): If argv[0] starts with “https://stackoverflow.com/” (absolute path) this is the path. Otherwise if argv[0] contains “https://stackoverflow.com/” (relative path) append it to cwd … Read more