Click to See Complete Forum and Search --> : difference between: Path.GetDirectoryName and Directory.GetCurrentDirectory


JohnIdol
January 26th, 2008, 08:38 PM
Hi Guys,

anyone could help me understand the difference between these two methods?



path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:/", ""));

path_Startup = System.IO.Directory.GetCurrentDirectory();


I am getting the same result.

I read something about shadow copies and Path.GetDirectoryName being more reliable because of that, but I couldn't find anything too clear.

Anyhelp would be appreciated.

Thanks,

Arjay
January 26th, 2008, 09:09 PM
While the CurrentDirectory typically is the same as the assembly location, it can be changed by calling SetCurrentDirectory. It can also be changed when the application is launched with the Process class (by setting the ProcessStartInfo.WorkingDirectory).

TheCPUWizard
January 26th, 2008, 09:17 PM
IIRC (and I am doing this from memory), there will also be differences when you have virtual mount points, substituted drives and/or other construct which make the "apparant" directory (what you would get with a "cd" from the command line) from the actual physical path.

Unfortunately I am not in a position to test this right now, but I believe that is what the documentation is referring to.

Arjay is also 100% correct in his point that the current directory may not be the directory where the assembly is located (either by having changed it from within the progran, or even by specifying a specific startup directory), but I do not think this is what the documentation is referring to.

JohnIdol
January 27th, 2008, 07:20 AM
Thanks for the help guys, now it's making much more sense.