Get-ChildItem中的多个过滤器

时间:2019-03-15 11:30:30

标签: powershell powershell-v3.0 copy-paste

到目前为止,我想在 PowerShall 脚本中应用多个filter,如下所示,我只能添加单个filter

Get-Childitem "D:\SourceFolder" -recurse -filter "*kps.jpg" | Copy-Item -Destination "D:\DestFolder"

从上面的查询中,我只能将一个文件 kps.jpg SourceFolder复制到DestFolder,我如何给多个名称复制一个文件?

1 个答案:

答案 0 :(得分:5)

要对多个条件进行过滤,请使用$host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="name"; // Database name $tbl_name="scores"; // Table name // Connect to server and select database. $conn= new mysqli($host, $username, $password, $db_name); // Retrieve data from database $sql="SELECT * FROM scores ORDER BY score DESC LIMIT 10"; $result=$conn->query($sql); $data = []; // Start looping rows in mysql database. while($rows = mysqli_fetch_assoc($result)){ $data[] = $rows; // close while loop } foreach ($data as $row){ echo $row['name'] . "|" . $row['score'] . "|"; } // close MySQL connection mysqli_close($conn); 参数而不是.hovercontainer { width: 500px; margin: 0 auto; position: relative; height: 170px; } .hovercontainer p{ position:absolute; top:50%; text-align: center; left:0; right:0; margin:0 auto; z-index:10; } .hovercontainer img{ width:90%; -webkit-transition: all .3s ease-in-out; -moz-transition: all .3s ease-in-out; -ms-transition: all .3s ease-in-out; -o-transition: all .3s ease-in-out; transition: all .3s ease-in-out; opacity:0; position: relative;} .hovercontainer p:hover ~ img{ opacity:1 } .hovercontainer p:hover{ opacity:0; }

    <div class="hovercontainer">
                    <p>Text</p>
                    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSU48ifXX9Kar3IFVrlfwx6UFLqaQno8rCebFvGtwk6yWky9_mz" alt="" />
                    </div>


注意:Include仅在您还指定-Filter或路径以Get-Childitem "D:\SourceFolder" -Recurse -Include "*kps.jpg", "*kps.png", "*kps.bmp" | Copy-Item -Destination "D:\DestFolder" 结尾(如Include

)时有效


注意2:正如Lee_Daily所言,-Recurse的工作速度比\*(或Get-Childitem "D:\SourceFolder\*")参数要快。筛选器比其他参数更有效,因为提供程序在cmdlet获取对象时将其应用。否则,PowerShell会在检索到对象后过滤它们。参见the docs

-Filter的缺点是只能提供一个文件名过滤器,而-Include则允许使用一组通配符过滤器。