Open Many Files With One Command

by Apr 7, 2011

To quickly open all files of a kind, such as all text or script files found in a folder, you should try the  Open-File function. It will accept a simple pattern, such as *.txt which opens all text files, or a*.ps1,which opens all PowerShell scripts that start with "a":

function Open-file{
  param(
    [Parameter(Mandatory=$true)]
    $path
  )
  $paths = Resolve-Path $path -ea SilentlyContinue
  if ($paths -ne $null) {
    $paths | Foreach-Object { Invoke-Item $_ }
  } else {
    "No file matched $path."
  }
}
PS > Open-File *.txt

 

Twitter This Tip!
ReTweet this Tip!