feat(scripts): 资源管理器右键菜单
- install-explorer-menu.ps1:注册 HKCU 右键项(文件夹 / 文件夹空白处 / mkv,mp4,avi 文件) - uninstall-explorer-menu.ps1:一键移除 - explorer-media-rename.ps1:菜单入口,文件取其所在目录,结束后可选暂停窗口 - media-rename.ps1:支持 MEDIA_RENAME_DRYRUN=1 环境变量,便于验证
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#Requires -Version 7.0
|
||||
<#
|
||||
.SYNOPSIS
|
||||
资源管理器右键菜单的入口:把选中的文件夹(或视频文件所在目录)交给 media-rename。
|
||||
|
||||
.DESCRIPTION
|
||||
由 install-explorer-menu.ps1 注册到:
|
||||
- 文件夹右键
|
||||
- 文件夹空白处右键(当前目录)
|
||||
- .mkv / .mp4 / .avi 文件右键(取其所在目录)
|
||||
|
||||
.PARAMETER Pause
|
||||
执行结束后停住窗口,便于查看输出(由右键菜单传入)。
|
||||
|
||||
.PARAMETER Paths
|
||||
资源管理器传入的选中项(通常一个)。
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch]$Pause,
|
||||
[Parameter(ValueFromRemainingArguments = $true)][string[]]$Paths = @()
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch { }
|
||||
|
||||
$target = $Paths | Where-Object { $_ } | Select-Object -First 1
|
||||
|
||||
if (-not $target) {
|
||||
Write-Host '❌ 没有收到要处理的路径' -ForegroundColor Red
|
||||
if ($Pause) { Write-Host ''; Read-Host '按 Enter 关闭' | Out-Null }
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (Test-Path -LiteralPath $target -PathType Leaf) {
|
||||
$target = Split-Path -Parent $target
|
||||
}
|
||||
|
||||
Write-Host "📁 目标: $target" -ForegroundColor DarkGray
|
||||
& (Join-Path $PSScriptRoot 'media-rename.ps1') -Tokens @($target)
|
||||
$code = $LASTEXITCODE
|
||||
if ($null -eq $code) { $code = 0 }
|
||||
|
||||
if ($Pause) {
|
||||
Write-Host ''
|
||||
Read-Host '按 Enter 关闭窗口' | Out-Null
|
||||
}
|
||||
exit $code
|
||||
Reference in New Issue
Block a user