- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000
- set "self=%~f0"
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal \"%~f0\"|Out-String|Invoke-Expression"
- pause
- exit
- #>
- $self=get-item -literal $env:self;
- $current=$self.Directory.FullName;
- $enc=[Text.Encoding]::GetEncoding('GB2312');
- $dic=@{};
- $files=@(dir -literal $current|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- $text=[IO.File]::ReadAllText($files[$i].FullName, $enc);
- $arr=$text.trim().split("`r`n", [StringSplitOptions]::RemoveEmptyEntries);
- if($arr.length -ge 3){
- $m1=[regex]::match($arr[1].trim(), '^\S+\s+(\d{4}\s+\d+\s+\d+\s+\d+)');
- $m2=[regex]::match($arr[$arr.length-1].trim(), '^\S+\s+(\d{4}\s+\d+\s+\d+\s+\d+)');
- if($m1.Success -and $m2.Success){
- $brr=$m1.groups[1].value -split '\s+';
- $crr=$m2.groups[1].value -split '\s+';
- $starttime='{0} {1} {2} {3}' -f $brr[0], $brr[1].PadLeft(2,'0'), $brr[2].PadLeft(2,'0'), $brr[3].PadLeft(2,'0');
- $endtime='{0} {1} {2} {3}' -f $crr[0], $crr[1].PadLeft(2,'0'), $crr[2].PadLeft(2,'0'), $crr[3].PadLeft(2,'0');
- $renge=$starttime+'-'+$endtime;
- if(-not $dic.ContainsKey($renge)){
- $drr=New-Object -TypeName System.Collections.ArrayList;
- $dic.add($renge, $drr);
- }
- [void]$dic[$renge].add($files[$i]);
- }
- }
- }
- foreach($k in $dic.Keys){
- $newfolder=$k+' ('+$dic[$k].count.toString()+')';
- $newpath=$current+'\'+$newfolder+'\';
- if(-not (test-path -literal $newpath)){[void][IO.Directory]::CreateDirectory($newpath);}
- for($i=0;$i -lt $dic[$k].count;$i++){
- write-host ($dic[$k][$i].Name+' --> '+$newfolder);
- move-item -literal $dic[$k][$i].FullName $newpath -force -ErrorAction SilentlyContinue;
- }
- write-host "`r`n";
- }
复制代码
|