CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2007
    Location
    Cork, Ireland
    Posts
    216

    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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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).

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    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

  4. #4
    Join Date
    Aug 2007
    Location
    Cork, Ireland
    Posts
    216

    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
  •  





Click Here to Expand Forum to Full Width

Featured