[MonoDevelop] Best way to find the current directory
Michael Hutchinson
m.j.hutchinson at gmail.com
Wed Apr 7 09:56:42 EDT 2010
On Wed, Apr 7, 2010 at 9:34 AM, Steve Ricketts <velocedge at hotmail.com> wrote:
>
> I'm using the following to find the current directory and any command line
> arguments.
>
> foreach (string arg in Environment.GetCommandLineArgs())
>
> {
>
> CommandLine = CommandLine + arg + " ";
>
> }
>
> Is there a better way to get the current (executable) directory within C#?
The executable's directory: Path.GetDirectoryName
(Assembly.GetEntryAssembly ().Location)
Working directory: Environment.CurrentDirectory
Directory of the assembly some type is in: Path.GetDirectoryName
(typeof(SomeType).Assembly.Location)
(assuming: using System; using System.Reflection; using System.IO;)
Btw, your example is rather odd - why join the arguments? Also,
concatenating strings in a loop is generally a bad practice as it
causes lots of garbage. Use string.Join or a StringBuilder.
--
Michael Hutchinson
http://mjhutchinson.com
More information about the Monodevelop-list
mailing list