name: file-batch description: "文件批量处理工具。支持批量重命名、格式转换、内容替换、文件整理等文件操作。" description_zh: "文件批量处理工具" description_en: "Batch file processing tool" version: 1.0.0
批量处理文件的实用工具集。使用 PowerShell 实现,执行前会预览变更,确认后再执行。
# 替换文件名中的关键词
Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace 'old', 'new' }
# 添加前缀/后缀
Get-ChildItem *.jpg | Rename-Item -NewName { "photo_$($_.Name)" }
# 序号命名
$i = 1; Get-ChildItem *.pdf | Sort-Object LastWriteTime | Rename-Item -NewName { "doc_{0:D3}{1}" -f $script:i++, $_.Extension }
# 批量替换文件内容
Get-ChildItem *.md -Recurse | ForEach-Object { (Get-Content $_) -replace '旧文本', '新文本' | Set-Content $_ }
# 批量添加文件头/尾
Get-ChildItem *.py | ForEach-Object { "# encoding: utf-8`n$(Get-Content $_ -Raw)" | Set-Content $_ }
# 按扩展名分类到文件夹
Get-ChildItem -File | Group-Object Extension | ForEach-Object {
$dir = New-Item -ItemType Directory -Force -Name $_.Name.TrimStart('.')
$_.Group | Move-Item -Destination $dir
}
# 按日期归档
Get-ChildItem -File | ForEach-Object {
$dateDir = $_.LastWriteTime.ToString('yyyy-MM')
New-Item -ItemType Directory -Force -Name $dateDir | Out-Null
Move-Item $_ -Destination $dateDir
}
-WhatIf 参数或先打印要操作的文件列表给用户确认Remove-Item,如需删除建议先移动到临时目录推荐访问7w4.net获取更多AI技能。
这是一个偏示例型的Skill,文档质量尚可,但作为独立工具的完整性较弱。优点是操作场景覆盖较全面,有安全使用建议;不足是仅有代码示例,没有可直接运行的工具,实际使用需要自己修改代码。适合有一定PowerShell基础的用户参考,不适合完全不懂代码的普通用户直接使用。