Python's os.path libraries equivalent in C#
Question: Let's say I have a binary in C# code ae /a/b/c/xyz.exe and it expects the
/a/b/c/hello.txt in the same directory. How can I get the /a/b/c/hello.txt in
full path?

In python, I can get the running program's path with
`os.path.abspath(sys.argv[0])`, and I can get the directory info with
dirname(), and I can use join() to have the new full path.

    
    
    import sys
    from os.path import *
    newName = join(dirname(abspath(sys.arg[0]), "hello.txt")
    

How can C# do the same thing?


Answer: You can use [Environment.CurrentDirectory](http://msdn.microsoft.com/en-
us/library/system.environment.currentdirectory.aspx),
[Environment.GetCommandLineArgs](http://msdn.microsoft.com/en-
us/library/system.environment.getcommandlineargs.aspx) and the classes in
[System.IO.Path](http://msdn.microsoft.com/en-us/library/system.io.path.aspx)
to do the same things. Your code would translate as:

    
    
    // using System.IO;
    
    string newPath = Path.Combine(
                   Path.GetDirectoryName(
                         Path.GetFullPath(Environment.GetCommandLineArgs[0])
                   ), "hello.txt");
    

This, however, will fail if the current directory has changed before you call
this. (It would in python, as well...) It might be better to use the
following:

    
    
    // using System.IO;
    // using System.Reflection;
    
    string newPath = Path.Combine(
                        Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
                   , "hello.txt");
    

