什么是Linq.First相当于在PowerShell中? [英] What is the Linq.First equivalent in PowerShell?
本文介绍了什么是Linq.First相当于在PowerShell中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码片段从文件列表其中哪些是对的Ftp目录检测
The snippet below detects from a list of files which of them is a Directory on Ftp
为C#它会像下面
var files = new List<string>(){"App_Data", "bin", "Content"};
var line = "drwxr-xr-x 1 ftp ftp 0 Mar 18 22:41 App_Data"
var dir = files.First(x => line.EndsWith(x));
我怎么能transalte在PowerShell中的最后一行?
How I can transalte the last line in PowerShell ?
推荐答案
这样的事情...
$files = @("App_Data", "bin", "Content")
$line = "drwxr-xr-x 1 ftp ftp 0 Mar 18 22:41 App_Data"
$dir = $files | Where { $line.EndsWith($_) } | Select -First 1
这些版本的最后一行将全部完成相同的:
These versions of the last line would all accomplish the same:
$dir = @($files | Where { $line.EndsWith($_) })[0]
$dir = $files | Where { $line.EndsWith($_) } | Select -index 0
$dir = $files | Where { $line.EndsWith($_) } | Select -First 1
这篇关于什么是Linq.First相当于在PowerShell中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文