Jump to content
  • Advertisement
Sign in to follow this  
nagromo

[.net] working directory

This topic is 5425 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

If I never change my working directory, is it safe to just use relative directories such as "Graphics\img001.png" instead of "C:\...\MyApp\Graphics\img001.png"?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by nagromo
If I never change my working directory, is it safe to just use relative directories such as "Graphics\img001.png" instead of "C:\...\MyApp\Graphics\img001.png"?


Yes, but never a good idea to just assume those directories are going to be there (i.e. someone might cwd before running your app) - best to check the cwd, and check for the existence of the directories / files.

Share this post


Link to post
Share on other sites
I use relative directories myself, but if I were making a program I planend to distribute, I'd have a "long" prefix of the full path name (that could be changed) and just tack the local directories on to the end of that.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
..or you could find the path in which your application is running with AppDomain.CurrentDomain.BaseDirectory

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
..or you could find the path in which your application is running with AppDomain.CurrentDomain.BaseDirectory
I'd (being another AP) say *should* rather than *could*. Current directory is an ugly thing to rely on, find out where your .exe is executing and build your absolute path from there.

Share this post


Link to post
Share on other sites
Quote:
Original post by Peon
I use relative directories myself, but if I were making a program I planend to distribute, I'd have a "long" prefix of the full path name (that could be changed) and just tack the local directories on to the end of that.

I don't like using relative paths either.
I am also never sure what uses the current directory. .NET functions obviously do, but do DirectX functions for example?

Share this post


Link to post
Share on other sites
So would this be a good way to do it:


public Texture(string xFilename) {
Bitmap lImage = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + xFilename);
CreateTextureFromBitmap(lImage);
}


Also, if this code was in a .dll (maybe in a different directory from the exe) would it still use the .exe's path?

Share this post


Link to post
Share on other sites
Mmm, not sure - I think it will use the path of the DLL. However Application.StartupPath() uses the path of the exe that started the process it is being called in. It doesn't include the exe's name in this string.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!