Welcome to MSDN Blogs Sign in | Join | Help

jaredpar's WebLog

Code, rants and ramblings of a programmer.

Syndication

News

Now Reading

Expert F#

What's a better book to read when learning F#?

Essential WPF

Thus far the best book I've read on WPF. Gets right down to working with WPF and the goals/history.

Purely Functional Data Structures

Reading this book makes me feel like I'm back in college. It will really get your mind going and is best read with a whiteboard handy.


Where is this script?

Scripts often need to dynamically find out what directory they are executed from.  In CMD scripts this is done by %~dp0.  For powershell the following will do the trick.

  split-path -parent $MyInvocation.MyCommand.Definition

 When this is run anywhere in the script body (not a function within the script) it will return the directory currently holding the running script.  If you execution this from a function within a script though, it will print out the body of the function.  If you need to know the directory of the script inside the body of the script, store it in script level variable.

  $script:mypath = $MyInvocation.MyCommand.Definition

  function printScriptPath() { return $script:mypath; }

 

Published Thursday, January 18, 2007 2:41 PM by Jared Parsons

Filed under:

Comments

No Comments

New Comments to this post are disabled
Page view tracker