本帖最后由 zaqmlp 于 2019-12-4 19:09 编辑
- <# :
- cls
- @echo off
- set info=互助互利,支付宝扫码头像,感谢赞助
- title %info%
- set "rootpath=%~dp0"
- if "%rootpath:~-1%" equ "\" (set "rootpath=%rootpath:~,-1%")
- cd /d "%rootpath%"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%rootpath%'"
- echo;%info%
- pause
- exit
- #>
-
- $ago=-1;
- $today=get-date;
- $agotime=get-date ($today.adddays($ago).toString('yyyy-MM-dd')+' 06:00:00');
- $newfolder=$args[0]+'\#result';
-
- if(-not (test-path -liter $newfolder)){[void](md $newfolder -force)};
- $files=@(dir -liter $args[0]|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i];
- [System.Collections.ArrayList]$list=@();
- $dic=New-Object 'System.Collections.Generic.Dictionary[string,Object]';
- $text=[IO.File]::ReadAllLines($files[$i].FullName,[Text.Encoding]::Default);
- for($j=0;$j -lt $text.count;$j++){
- if($text[$j].Contains('[ 档案')){
- $arr=$text[$j].trim() -split '时间:';
- if($arr[1] -ne ''){
- $dt=get-date $arr[1];
- if($dt -ge $agotime){
- $line=$text[$j].trim().replace('ID:','') -replace ' \[ 档案 上传|\] 文件:\(|\) 次数:| 时间:',',';
- $brr=$line.split(',');
- if(-not $dic.ContainsKey($brr[0])){
- $crr=@{
- '100001'=@{'成功'=0;'失败'=0};
- '100002'=@{'成功'=0;'失败'=0};
- '100003'=@{'成功'=0;'失败'=0};
- '100004'=@{'成功'=0;'失败'=0}
- };
- $dic.add($brr[0], $crr);
- }
- $dic[$brr[0]][$brr[2]][$brr[1]]++;
- [void]$list.add($line);
- };
- };
- };
- };
- [IO.File]::WriteAllLines($files[$i].FullName, $list, [Text.Encoding]::Default);
-
- $newfile=$newfolder+'\'+$files[$i].BaseName+'_'+$today.toString('yyyy-MM-dd')+'_结果.txt';
- [System.Collections.ArrayList]$list=@();
- foreach($a in $dic.Keys){
- $b=$dic[$a]['100001']['成功']+$dic[$a]['100001']['失败']+$dic[$a]['100002']['成功']+$dic[$a]['100002']['失败'];
- $line=$a+'上传100001成功'+$dic[$a]['100001']['成功']+'次,失败'+$dic[$a]['100001']['失败']+'次;上传100002成功'+$dic[$a]['100001']['成功']+'次,失败'+$dic[$a]['100001']['失败']+'次,共上传'+$b+'次';
- [void]$list.add($line);
- $c=$dic[$a]['100003']['成功']+$dic[$a]['100003']['失败']+$dic[$a]['100004']['成功']+$dic[$a]['100004']['失败'];
- $line=$a+'上传100003成功'+$dic[$a]['100003']['成功']+'次,失败'+$dic[$a]['100003']['失败']+'次;上传100004成功'+$dic[$a]['100004']['成功']+'次,失败'+$dic[$a]['100004']['失败']+'次,共上传'+$c+'次';
- [void]$list.add($line);
- if($b -eq 0){
- [void]$list.add($a+'上传100001、100002零次');
- }else{
- $d=$dic[$a]['100001']['成功']+$dic[$a]['100002']['成功'];
- if($d -eq 0){
- [void]$list.add($a+'上传100001、100002完全失败');
- }else{
- [void]$list.add($a+'上传100001、100002'+$b+'次,成功'+$d+'次,结余'+($b-$d*3));
- };
- };
- if($c -eq 0){
- [void]$list.add($a+'上传100003、100004零次');
- }else{
- $d=$dic[$a]['100003']['成功']+$dic[$a]['100004']['成功'];
- if($d -eq 0){
- [void]$list.add($a+'上传100003、100004完全失败');
- }else{
- [void]$list.add($a+'上传100003、100004'+$c+'次,成功'+$d+'次,结余'+($c-$d*3));
- };
- };
- };
- [IO.File]::WriteAllLines($newfile, $list, [Text.Encoding]::Default);
- }
复制代码
|