纪要时间.txt格式:- 1315300183620200608143825
- 1395300183620200608183559
- 1885300183620200609071154
- 1865300183620200607235937
- 1865300183620200609112900
- 1585300183620200609213544
- 1315300183620200608113825
- 1865300183620200607025937
-
- 1865300183620200607082005
- 1315300183620200608143325
- 1585300183620200609110533
复制代码 录音文件扩展名是.wav
纪要文件与录音文件同目录下
保存代码为.bat,放到纪要文件同目录下运行.请先测试- <#*,:&cls
- @echo off
- pushd "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- # 更改通话录音文件名,使之与纪要时间保持一致.
- $RecordTimeFile = "纪要时间.txt"
- $RecordWavs = "*.wav"
- function ParseDateTime {
- param (
- [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
- [ValidateLength(14, 14)]
- [string]$strdtm
- )
- New-Object System.DateTime -ArgumentList @(
- [int]$strdtm.SubString(0, 4),
- [int]$strdtm.SubString(4, 2),
- [int]$strdtm.SubString(6, 2),
- [int]$strdtm.SubString(8, 2),
- [int]$strdtm.SubString(10, 2),
- [int]$strdtm.SubString(12, 2),
- [System.DateTimeKind]::Local)
- }
- $gHashWavs = Get-ChildItem $RecordWavs -OutBuffer 100 | Select-Object -Property @{
- Name = "FileInfo"
- Expression = { $_ }
- }, @{
- Name = "PhoneNumber"
- Expression = { $_.BaseName.SubString(0, 11) }
- }, @{
- Name = "RecordTime"
- Expression = { ParseDateTime $_.BaseName.SubString(11, 14) }
- } -OutBuffer 100 | Group-Object -Property 'PhoneNumber' -AsHashTable -AsString
-
- # $gHashWavs
-
- Get-Content -Path $RecordTimeFile -OutBuffer 100 | ForEach-Object {
- try {
- $PhoneNumber = $_.SubString(0, 11)
- $dtm = ParseDateTime $_.SubString(11, 14)
- if ($gHashWavs.ContainsKey($PhoneNumber)) {
- if ($gHashWavs[$PhoneNumber].Count -eq 0) {
- Write-Host "找不到匹配纪要时间 $_ 的录音文件." -foregroundcolor Red
- } else {
- $minTicks = [System.Int64]::MaxValue
- foreach ($item in $gHashWavs[$PhoneNumber]) {
- $ticks = [math]::Abs(($item.RecordTime - $dtm).Ticks)
- if ($ticks -lt $minTicks) {
- $wav2Rename = $item
- $minTicks = $ticks
- }
- }
- Rename-Item -Path $wav2Rename.FileInfo.PSPath -NewName ($_ + $wav2Rename.FileInfo.Extension) -Verbose
- [void]$gHashWavs[$PhoneNumber].Remove($wav2Rename)
- }
- } else {
- Write-Host -Message "不存在手机号 ${PhoneNumber} 的录音文件." -foregroundcolor Red
- }
- } catch {
-
- }
- }
-
- # $gHashWavs
复制代码
|