]> git.ardis.lu - ArdisUtilities/commitdiff
Add Open-ParentFolder
authorArdis Lu <ardisglu@gmail.com>
Thu, 26 Oct 2023 03:53:06 +0000 (20:53 -0700)
committerArdis Lu <ardisglu@gmail.com>
Thu, 26 Oct 2023 03:53:06 +0000 (20:53 -0700)
ArdisUtilities/ArdisUtilities.psd1
ArdisUtilities/ArdisUtilities.psm1

index 6696a4563c8fc06e69ef6d1c8e89ec7490a4ca2f..3ec3adfd14c029ada54105fad89cccc106b76aad 100644 (file)
@@ -4,7 +4,7 @@
   GUID              = '57a6bea3-0ea5-44b3-95d2-71d122772f1c'
   Author            = 'Ardis Lu'
   Description       = 'My personal utility functions.'
-  FunctionsToExport = @('Invoke-RandomFile', 'ConvertTo-Base64String', 'Get-StringHash', 'Get-SizeDurationRatio', 'Get-ExtendedFileProperty', 'Get-DocumentationIP', 'Get-DocumentationPhoneNumber', 'Test-TcpPort', 'Get-HelpAsMarkdown')
+  FunctionsToExport = @('Invoke-RandomFile', 'ConvertTo-Base64String', 'Get-StringHash', 'Get-SizeDurationRatio', 'Get-ExtendedFileProperty', 'Get-DocumentationIP', 'Get-DocumentationPhoneNumber', 'Test-TcpPort', 'Get-HelpAsMarkdown', 'Open-ParentFolder')
   CmdletsToExport   = @()
   VariablesToExport = @()
   AliasesToExport   = @()
index 31bd77e8acc57c04da80092921fef516eaf1a11a..c9ec96aca94aa0a1f6bff822a252c0c9c2398ad9 100644 (file)
@@ -807,3 +807,36 @@ function Get-HelpAsMarkdown {
     $output -Join "`r`n"
   }
 }
+
+function Open-ParentFolder {
+  <#
+  .SYNOPSIS
+    Opens File Explorer (explorer.exe) in the folder that contains a command.
+
+  .DESCRIPTION
+    Uses Get-Command to determine the path to an executable, then passes the path to Split-Path to get the
+    parent folder. Finally, opens the parent folder by passing the path as an argument to explorer.exe.
+
+  .PARAMETER Command
+    The name of the executable to open the File Explorer to.
+
+  .EXAMPLE
+    PS> Open-ParentFolder curl
+
+    Opens File Explorer to C:\Windows\system32\.
+  #>
+
+  [CmdletBinding()]
+  param(
+    [Parameter(Mandatory, ValueFromPipeline)]
+    [String]$Command
+  )
+
+  begin {
+    $ErrorActionPreference = 'Stop'
+  }
+  
+  process {
+    explorer.exe ((Get-Command $Command).Source | Split-Path -Parent)
+  }
+}
This page took 0.036112 seconds and 4 git commands to generate.