Jump to content
  • Advertisement
Sign in to follow this  
SelethD

getting directory in c# problem

This topic is 3591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to access data files for my game, that are located in the same place as the .exe I am using Vis C# 2008 and tried to use System.IO.Directory.GetCurrentDirectory This worked fine in testing, however once I installed my game and try to run the game from a desktop shortcut... The application is getting the path to my desktop and therefore cant find my data files Same from the start menu, then only time it works is when I go into c:\program files\mygame Is there a better way for me to find the directory of my executable? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by SelethD
I need to access data files for my game, that are located in the same place as the .exe

I am using Vis C# 2008 and tried to use System.IO.Directory.GetCurrentDirectory

This worked fine in testing, however once I installed my game and try to run the game from a desktop shortcut... The application is getting the path to my desktop and therefore cant find my data files

Same from the start menu, then only time it works is when I go into c:\program files\mygame
Is there a better way for me to find the directory of my executable?

Thank you.
The Win32/C++ way is via GetModuleFileName, and then trim off the filename from the path. I presume there's something similar in .NET.

Share this post


Link to post
Share on other sites
Ok , thanks. I found that the equivalent is

System.Windows.Forms.Application.ExecutablePath

so now i just need to find a way to trim the filename off the path.

Thanks again.

Share this post


Link to post
Share on other sites
Look into Path.GetDirectory or Path.GetFilename you can use some .Trim functions to pretty much do whatever you need. (System.IO.Path)

http://msdn.microsoft.com/en-us/library/system.io.path.aspx

Or you can use AppDomain.CurrentDomain.BaseDirectory to get the directory of which your exe was launched from.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!