[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 zaqmlp 于 2020-8-27 22:44 编辑
  1. <# :
  2. cls
  3. @echo off
  4. cd /d "%~dp0"
  5. powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~f0'"
  6. pause
  7. exit
  8. #>
  9. $self=get-item -liter $args[0];
  10. $path=$self.Directory.FullName;
  11. $file1=".\jiansi.txt";
  12. $file2=".\caifen.txt";
  13. $file3=".\dengsi.txt";
  14. $file1=$file1 -replace '^\.',$path;
  15. $file2=$file2 -replace '^\.',$path;
  16. $file3=$file3 -replace '^\.',$path;
  17. if(-not (test-path -liter $file1)){Write-host ('"'+$file1+'" not found');exit;};
  18. if(-not (test-path -liter $file2)){Write-host ('"'+$file2+'" not found');exit;};
  19. $enc=New-Object System.Text.UTF8Encoding $False;
  20. $text1=[IO.File]::ReadAllLines($file1,$enc);
  21. $text2=[IO.File]::ReadAllLines($file2,$enc);
  22. $dic1=New-Object 'System.Collections.Generic.Dictionary[string,Object]';
  23. for($i=0;$i -lt $text2.count;$i++){
  24.     $arr=$text2[$i].trim().split('@!',2);
  25.     if($arr.length -ge 2){
  26.         $brr=$arr[1].toCharArray();
  27.         if(-not $dic1.ContainsKey($arr[0])){
  28.             $dic1.add($arr[0],$brr);
  29.         };
  30.     };
  31. };
  32. [System.Collections.ArrayList]$tmp=@();
  33. function cf($v){
  34.     if($dic1.ContainsKey($v)){
  35.         for($j=0;$j -lt $dic1[$v].length;$j++){
  36.             $c=($dic1[$v][$j]).toString();
  37.             cf $c;
  38.         };
  39.     }else{
  40.         [void]$tmp.add($v);
  41.     };
  42. };
  43. $fs=New-Object System.IO.FileStream($file3, [System.IO.FileMode]::Create);
  44. $sw=New-Object System.IO.StreamWriter($fs, $enc);
  45. for($i=0;$i -lt $text1.count;$i++){
  46.     write-host $text1[$i];
  47.     $arr=$text1[$i].trim().split('-',2);
  48.     if($dic1.ContainsKey($arr[0])){
  49.         cf $arr[0];
  50.         [System.Collections.ArrayList]$brr=@();
  51.         for($k=0;$k -lt $tmp.count;$k++){
  52.             if($tmp[$k] -ne $arr[1]){[void]$brr.add($tmp[$k]);};
  53.         };
  54.         $line=$text1[$i]+'='+($brr -join '');
  55.         $sw.WriteLine($line);
  56.     }else{
  57.         $sw.WriteLine($text1[$i]);
  58.     };
  59.     $sw.Flush();
  60.     $tmp.Clear();
  61. };
  62. $sw.Close();
  63. $fs.Close();
复制代码
1

评分人数

提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 6# lxh623 哪个没有算出减法
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 9# lxh623
有些字符识别不了,没办法正确拆分
  1. <# :
  2. cls
  3. @echo off
  4. cd /d "%~dp0"
  5. powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~f0'"
  6. pause
  7. exit
  8. #>
  9. $self=get-item -liter $args[0];
  10. $path=$self.Directory.FullName;
  11. $file1=".\jiansi.txt";
  12. $file2=".\caifen.txt";
  13. $file3=".\dengsi.txt";
  14. $file1=$file1 -replace '^\.',$path;
  15. $file2=$file2 -replace '^\.',$path;
  16. $file3=$file3 -replace '^\.',$path;
  17. if(-not (test-path -liter $file1)){Write-host ('"'+$file1+'" not found');exit;};
  18. if(-not (test-path -liter $file2)){Write-host ('"'+$file2+'" not found');exit;};
  19. $enc=New-Object System.Text.UTF8Encoding $False;
  20. $text1=[IO.File]::ReadAllLines($file1,$enc);
  21. $text2=[IO.File]::ReadAllLines($file2,$enc);
  22. $dic1=New-Object 'System.Collections.Generic.Dictionary[string,Object]';
  23. for($i=0;$i -lt $text2.count;$i++){
  24.     $arr=$text2[$i].split('@!:', 2);
  25.     if($arr.length -ge 2){
  26.         if(-not $dic1.ContainsKey($arr[0])){
  27.             [System.Collections.ArrayList]$tmp=@();
  28.             $dic1.add($arr[0], $tmp);
  29.         };
  30.     };
  31.     [void]$dic1[$arr[0]].add($text2[$i]);
  32. };
  33. $fs=New-Object System.IO.FileStream($file3, [System.IO.FileMode]::Create);
  34. $sw=New-Object System.IO.StreamWriter($fs, $enc);
  35. for($i=0;$i -lt $text1.count;$i++){
  36.     write-host $text1[$i];
  37.     $arr=$text1[$i].split('-', 2);
  38.     if($dic1.ContainsKey($arr[0])){
  39.         $line=$text1[$i];
  40.         for($j=0;$j -lt $dic1[$arr[0]].count;$j++){
  41.             $brr=$dic1[$arr[0]][$j].split('@!:', 2);
  42.             $t=$brr[1].replace($arr[1], '');
  43.             if($brr[1] -ne $t){
  44.                 $line=$line+'='+$t;
  45.                 break;
  46.             };
  47.         };
  48.         $sw.WriteLine($line);
  49.     }else{
  50.          $sw.WriteLine($text1[$i]);
  51.     };
  52.     $sw.Flush();
  53. };
  54. $sw.Close();
  55. $fs.Close();
复制代码
1

评分人数

提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表