PowerShell How to open multiple files at once _powershell

Source: Internet
Author: User

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:

PS >open-file *.log

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.