|
-
January 26th, 2008, 09:38 PM
#1
difference between: Path.GetDirectoryName and Directory.GetCurrentDirectory
Hi Guys,
anyone could help me understand the difference between these two methods?
Code:
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,
JI
-
January 26th, 2008, 10:09 PM
#2
Re: difference between: Path.GetDirectoryName and Directory.GetCurrentDirectory
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).
-
January 26th, 2008, 10:17 PM
#3
Re: difference between: Path.GetDirectoryName and Directory.GetCurrentDirectory
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.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
January 27th, 2008, 08:20 AM
#4
Re: difference between: Path.GetDirectoryName and Directory.GetCurrentDirectory
Thanks for the help guys, now it's making much more sense.
JI
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|