保存为 重命名epub.bat,编码是ANSI.- <#*,:
- @echo off
- cd /d "%~dp0"
- set "batchfile=%~f0"
- Powershell -ExecutionPolicy Bypass -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create([IO.File]::ReadAllText($env:batchfile,[Text.Encoding]::GetEncoding(0) )) )"
- pause
- exit /b
- #>
- #
- # a.txt内容放这里
- $a = @'
- T17n0784--四十二章经--後汉 迦叶摩腾共法兰译
- T39n1794--注四十二章经--宋 真宗皇帝注
- X37n0669--四十二章经注--宋 守遂注 明 了童补注
- X37n0670--四十二章经解--明 智旭著
- X37n0671--四十二章经疏钞--清 续法述
- '@
-
- $arr = $a.Trim() -split '[\r\n]+'
- Add-Type -AssemblyName Microsoft.VisualBasic
-
- # 繁体转简体
- Get-ChildItem -Path . | Where-Object { $_ -is [IO.FileInfo] -and $_.FullName -ne $env:batchfile -and $_.Name -ne 'a.txt' } | Rename-Item -NewName {
- [Microsoft.VisualBasic.Strings]::StrConv($_.Name, [Microsoft.VisualBasic.VbStrConv]::SimplifiedChinese, 0)
- } -Verbose -ErrorAction SilentlyContinue
-
- # 文件名含有002、003及以上的,移动到新建文件夹
- $di = [IO.Directory]::CreateDirectory('新建文件夹')
- Get-ChildItem -Path . | Where-Object { $_ -is [IO.FileInfo] -and $_.FullName -ne $env:batchfile -and $_.Name -ne 'a.txt' -and $_.Name -match '\b\d{3}\b' } | Move-Item -Destination ($di.FullName) -Verbose
-
- # 最开始到空格的字符,前后加上--,去搜索文本a,找到,就重新命名
- Get-ChildItem -Path . | Where-Object { $_ -is [IO.FileInfo] -and $_.FullName -ne $env:batchfile -and $_.Name -ne 'a.txt' } | Rename-Item -NewName {
- $k = ($_.BaseName -split '\s+')[0]
- $newBaseName = $arr -match "--$([regex]::Escape(${k}))--" | Select-Object -First 1
- if ($newBaseName) {
- $newBaseName + $_.Extension
- } else {
- $_.Name
- }
- } -Verbose -ErrorAction SilentlyContinue
复制代码
|