Sometimes we want to open multiple files, especially all files with the same suffix name, through the PowerShell script. Let's write a function called Open-file, which, by passing a *. suffix to this function, implements a one-time file that opens all of the suffix.
Copy Code code as follows:
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."
}
}
Before calling, let's explain. First, we define a function called Open-file, which has a $path parameter, which is required. Then, using the Resolve-path method, the path containing the wildcard character is converted to an array of objects with a real path. Finally, loop the array, using the Invoke-item method, to open each object in the array.
Let's see how to call this function open-file that opens multiple files at once.
Copy Code code as follows:
The function of this call statement is to open the file for all the. Log suffixes in the current directory.
Well, today this one-time open multiple files script is written to this, thanks to the small series of support!