[Mono-dev] System.Environment.CurrentDirectory problem

Adar Wesley adar.wesley at gmail.com
Thu Jul 23 15:10:03 EDT 2009


Hi,

System.Environment.CurrentDirectory is inherited from the calling process.
This is probably your shell.

Try looking at AppDomain.CurrentDomain.BaseDirectory or
Assembly.GetExecutingAssembly().CodeBase

Maybe that's what your looking for.

---
Adar Wesley


On Thu, Jul 23, 2009 at 7:18 PM, PFJ <pjohnson1 at uclan.ac.uk> wrote:

>
> Hi,
>
> I've compiled an application which tests for a directory and if it doesn't
> exist, creates it and copies a configuration file over.
>
> The app compiles fine. I've copied the executable and the configuration
> directory/file over to a new directory. When I run the app though, it
> creates a new directory in /home/paul rather than the directory it is being
> run from.
>
> When I've added in some debugging code, it seems that it think that the
> currentdirectory is /home/paul and not /home/paul/marker.
>
> I'm using the following code which seems to be misbehaving!
>
> 8-->
>                        string path = System.Environment.CurrentDirectory;
>                        string sep = Path.DirectorySeparatorChar.ToString();
>                        string dirpath = path +
> string.Format("{0}Resources", sep);
>                        string final = dirpath +
> string.Format("{0}configure.xml", sep);
>
>                        DialogResult ress;
>                        ress = MessageBox.Show(this, path, "create - path",
> MessageBoxButtons.OK);
>                        ress = MessageBox.Show(this, dirpath, "create -
> dir",
> MessageBoxButtons.OK);
>
>                        if (!Directory.Exists(dirpath))
>                        {
>                                ress = MessageBox.Show(this, "Directory no
> exist", "create",
> MessageBoxButtons.OK);
>                                Directory.CreateDirectory(dirpath);
>                        }
> <--8
>
> path is only returning /home/paul which isn't the expected behaviour. Is
> anyone else seeing this or is it me?
>
> I'm using mono-2.4.2.2
>
> TTFN
>
> Paul
> --
> View this message in context:
> http://www.nabble.com/System.Environment.CurrentDirectory-problem-tp24629353p24629353.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090723/601ea245/attachment.html 


More information about the Mono-devel-list mailing list