在向窗口发送Ctrl-4的同时,我使用以下脚本使用媒体播放器classic播放播放列表。
mpc-hc.exe playlist.m3u /play
[void][System.reflection.assembly]::loadwithpartialname('system.Windows.forms')
Foreach ($line in get-content
playlist.m3u) {
If ($line.substring($line.length-5,1) -match 2) {
[System.Windows.forms.Sendkeys]::sendwait("^4")
}
}快捷键Ctrl-4显示播放的文件的信息,但我只想它为第二个文件,这个脚本做它的所有文件播放,有解决方案吗?
发布于 2018-09-26 04:31:09
重构您的代码,以便可以在ISE或VSCode中进行调试。像这样:
$files = Get-Content playlist.m3u和
$file = $files[1] # the 2nd one那么您可能不需要foreach。如果没有更多的上下文,就很难提供完整的解决方案,也许上面的信息就足以解锁你。
编辑更改要求的每个注释...
使您的代码适应如下内容:
$files = @(
'one'
'two'
'three'
'four'
'five'
)
$isEvenIndex = $false
foreach ($file in $files)
{
if ($isEvenIndex)
{
# do your stuff
Write-Output "$file"
}
$isEvenIndex = !$isEvenIndex
}https://stackoverflow.com/questions/52506102
复制相似问题