4 ms·
Now I am curious :) I thought you just needed to do something like: $(ls $PSCommandPath).Directory (Not that that isnt longer than %~dp0; but I am curious wha
by shadowfox 13y ago
Now I am curious :)
I thought you just needed to do something like:
$(ls $PSCommandPath).Directory
(Not that that isnt longer than %~dp0; but I am curious what the 5 lines actually does)
- skrebbel 13y agoAt the time, I ended up googling for something like: function Get-Script-Directory { $scriptInvocation = (Get-Variable MyInvocation -Scope 1).Value return Split-Path $scriptInvocation.MyCommand.Path } I found that [1] lists a one-liner too, but that's also a four-liner if you'd turn it into a function. Still, I can't remember that shit by heart. I don't want to. Why do I have to? Did these people ever even use Powershell themselves? [1] http://stackoverflow.com/questions/5466329/whats-the-best-way-to-determine-the-location-of-the-current-powershell-script http://stackoverflow.com/questions/5466329/whats-the-best-wa... Sidenote: if something like node.js, entirely designed for fast asynchronous networking, despite all its callback hell and whatnot, is a better and more user-friendly Windows scripting host than Powershell, some people really should start to worry. Maybe if Powershell had something like npm, including its (simply perfect) install-to-current-directory-by-default, people could fix all the holes MS left behind. I might even start to like it then.