首页 > Web开发 > 详细

Windows Powershell Foreach 循环

时间:2016-01-30 16:25:01      阅读:326      评论:0      收藏:0      [点我收藏+]

下面举两个例子:

复制代码 代码如下:

$array=7..10
foreach ($n in $array)
{
    $n*$n
}
 
#49
#64
#81
#100
 
foreach($file in dir c:\windows)
{
    if($file.Length -gt 1mb)
    {
        $File.Name
    }
}
 
#explorer.exe
#WindowsUpdate.log

这里只为了演示foreach,其实上面的第二个例子可以用Foreach-Object更简洁。

复制代码 代码如下:

PS C:\Powershell> dir C:\Windows | where {$_.length -gt 1mb} |foreach-object {$_.Name}
explorer.exe
WindowsUpdate.log

Windows Powershell Foreach 循环

原文:http://www.jb51.net/article/55902.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!