我是PowerShell的新手,正在尝试适应奇怪的语法。我正在尝试删除文件夹路径数组。这就是我在C#中的做法:
string[] folders = { '~/MyFolder/Test123', '~/MyFolder/Test987', '~/MyFolder/Test333' };
foreach (string item in folders) {
$_.Remove()
}
如何在PowerShell中完成此操作?我找到了以下脚本,但不确定如何更改以使用预定义的数组。实际包含的参数来自NuGet:
param($installPath, $toolsPath, $package, $project)
$DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'Controllers'}|ForEach-Object{$_.Remove()}
我如何将一个字符串数组而不是硬编码的“Controllers”名称合并到其中。
最佳答案
这是将字符串数组应用于该过滤器的一种方法:
$ProjectItems = 'Controllers','Robots','Weapons','Bacon'
$DTE.Solution.Projects|
Select-Object -Expand ProjectItems|
Where-Object{$ProjectItems -contains $_.Name}|
ForEach-Object{$_.Remove()}
关于powershell - 在PowerShell中使用数组删除文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423884/