Home
Options

Question about the working directory

Hey all,

I found a post on seqanswers asking about this, and tried searching the forums here for that post, but couldn't find it. I hope this question isn't redundant.

I'm using Linqpad 4, and really like it. A problem I'm running into is related to the working directory. From what I can tell, it's in C:\Program Files\Linq, and not the folder which the query is saved in. Is it possible to set the current working directory, for this script, to the same directory where it's saved at?

The reason is because I'm doing some file IO, and am using this same script across multiple machines. Having a non-relative path makes that difficult, since the directory structure among the machines is different. I also version control these scripts, and include them with the source of my project.

Thanks,

-David

Comments

  • Options
    Yes: you can start your query as follows:

    Directory.SetCurrentDirectory (Path.GetDirectoryName (Util.CurrentQueryPath));

    One thing to be aware of, though, is that LINQPad runs all your queries in a single process, and the "current directory" is global to the process. So if you simultaneously run another query that changes the current directory, it could break.

    If you're using the command-line version of LINQPad (lprun) to execute the script, you won't get this problem because there's always a separate process per script. Also, with lprun, you shouldn't need to set the current directory because it will preserve whatever the current directory was when you invoked it.
  • Options

    Directory.SetCurrentDirectory (Path.GetDirectoryName (Util.CurrentQueryPath));

    That is all I ever want to do on any script.

Sign In or Register to comment.