【发布时间】:2021-04-27 18:36:00
【问题描述】:
我这里有这个脚本:
$directory = "C:\New Folder"
$counter = 1
Set-Location $directory
#Menu
Write-Host "==========" -BackgroundColor DarkGreen
Write-Host "===MENU===" -BackgroundColor DarkGreen
Write-Host "==========" -BackgroundColor DarkGreen
#Shows only .wav files and it order them
Get-ChildItem -Name -Include *.wav | ForEach-Object {Write-Host "[$counter] " -ForegroundColor Green -NoNewLine; Write-Host "$_"; $counter++}
Write-Host ""
$input = Read-Host -Prompt "Select a file from the menu"
Clear-Host
Write-Host "You have just selected: $input"
此时我想显示所选文件的名称。我怎么能这样做?
【问题讨论】:
-
不使用计数器,只使用数组索引。然后您可以通过
$FileList[$Index]调用任何项目。例如,lookee ... function_Get-MenuChoice [simplified] - Pastebin.com — pastebin.com/KMu2G9Dq -
@Lee_Dailey 这对我来说有点太棘手了,我不太明白,但还是谢谢你。我很感激
-
不客气! [grin] 我认为我的解决方案更简单,但它的基本思想相同。无论如何,我很高兴知道您的工作已按需要进行。
标签: powershell menu foreach-object