Created
January 5, 2017 05:47
-
-
Save bender-the-greatest/a5994e06004bd64aea435ab6083153ea to your computer and use it in GitHub Desktop.
Powershell function which opens the containing folder of a given file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Powershell function which opens the containing folder of a given file | |
# in the default program (this will be Windows Explorer 99% of the time). | |
# | |
# Note that if -File is actually a folder, it will open that folder's | |
# parent folder. | |
# | |
# Usage: | |
# Open-ContainingFolder $env:AppData | |
# Open-ContainingFolder .\somefile.txt | |
# Open-ContainingFolder C:\Windows\System32\ping.exe | |
function Open-ContainingFolder { | |
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$File | |
) | |
if (Test-Path -LiteralPath $File) { | |
Invoke-Item $(Split-Path -Parent $File) | |
} else { | |
$host.ui.WriteErrorLine("$File does not exist") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment