我想在此MKVMerge脚本中添加文件夹浏览器对话框。我不知道如何获取对话框的结果来指定脚本的目标目录。有人可以帮我整合一下吗?
#Set MKVMerge.exe Path
$MKVMerge = 'C:\Program Files\MKVToolNix\mkvmerge.exe'
#Set Target
$Directory = *this*
$SubExtension = Read-Host 'Input Sub Extension'
#Process
$Subs = Get-ChildItem $Directory -Filter "*.$SubExtension" -Recurse | % {
$_.FullName } | Sort-Object
$Count = $Subs.count
Write-Host "$Count MKV's to be processed."
Foreach ($Sub in $Subs) {
#Get File Name
$FormatName = $Sub.ToString()
#$Name = $FormatName.TrimEnd(".$SubExtension")
$Name = $FormatName.Substring(0,$FormatName.Length-($SubExtension.Length+1))
$MKV = $Name + '.mkv'
#Set Output File Name
$Output = $Name + '___MERGED' + '.mkv'
#Execute
& $MKVMerge -o "$Output" --default-track "0" --language "0:eng" "$Sub"
"$MKV"
If (Test-Path $Output) {
#Clean Up
Remove-Item $MKV
Remove-Item $Sub
Rename-Item $Output -NewName $MKV
} Else {
write-host "NON-EXISTENT - $Output" -foreground "red"
"NON-EXISTENT - $Output" | Out-File $Directory + "Errors.txt" -Append
}
}
文件夹对话框脚本:
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath
答案 0 :(得分:0)
这应该非常接近(只是脚本的开头):
#Set MKVMerge.exe Path
$MKVMerge = 'C:\Program Files\MKVToolNix\mkvmerge.exe'
#Set Target
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
[void]$FolderBrowser.ShowDialog()
$Directory = $FolderBrowser.SelectedPath