返回列表 发帖
  1. <# :
  2. @echo off
  3. PowerShell ". ([ScriptBlock]::Create((gc -Literal '%~f0') -join \"`r`n\")) '%~dp0'"
  4. pause & exit
  5. #>
  6. While (($myInput = Read-Host 'Input a Number') -notMatch '^[123][123]$') {
  7.     echo 'Input Error!';
  8. }
  9. $HashTab = @{'1'='C0_E0,1,0,0,'; '2'='C0_E0,2,0,0,'; '3'='C0_E0,3,0,1,'}
  10. $reg     =[regex]'(?i)C0_E0,[123],0,[01],';
  11. $replace = {
  12.     $key = $myInput.SubString($global:n, 1);
  13.     $global:n += 1;
  14.     $HashTab[$key];
  15. }
  16. forEach ($file In (dir -Literal $args[0] -Filter *.rcp)) {
  17.     If ($file -is [IO.FileInfo] -and $file.BaseName -notMatch '04T') {
  18.         $global:n = 0;
  19.         $s = (gc -Literal $file.FullName -ReadCount 0) -join "`r`n";
  20.         If ($reg.Matches($s).Count -gt 1) {
  21.             $s = $reg.Replace($s, $replace, 2);   #Replace Only 2 Times
  22.             sc -Literal $file.FullName -Value $s;
  23.         }
  24.     }
  25. }
复制代码

TOP

回复 28# qixiaobin0715


    如果提示输入错误次数超过32次,可能会报语法错误。因为变量延迟递归层数限制在32以内。
当然这是从批处理语法上说的,实际中没人会一直输入错误。

TOP

本来不想再在这个帖子浪费时间,想想还是贴出来,其他人有可能会参考一下下。
  1. @if(0)==(0) echo off
  2. for %%i in (11 12 13 21 22 23 31 32 33) do set _%%i=1
  3. :Loop
  4. set /p "Input=Input a Number:"
  5. setlocal enabledelayedexpansion
  6. if not defined _!Input! (
  7.     endlocal
  8.     echo;Input Error
  9.     goto :Loop
  10. ) else (
  11.     endlocal
  12.     dir /b /a-d *.rcp | findstr /i /v "04T" | cscript -nologo -e:jscript "%~f0" "%Input%"
  13. )
  14. pause & exit
  15. @end
  16. var arg = WSH.Arguments(0);
  17. var arr = ['C0_E0,1,0,0', 'C0_E0,2,0,0', 'C0_E0,3,0,1'];
  18. var reg = new RegExp('C0_E0,[123],0,[01]', 'ig');
  19. var fso = new ActiveXObject('Scripting.FileSystemObject');
  20. var replacement = function(s0) {
  21.     var i = arg.substr(n, 1);
  22.     n += 1;
  23.     return n<=2 ? arr[i-1] : s0;  //replace only 2 times
  24. }
  25. while (!WSH.StdIn.AtEndOfStream) {
  26.     var n = 0;
  27.     var f = WSH.StdIn.ReadLine();
  28.     var objFile = fso.OpenTextFile(f, 1);
  29.     var s = objFile.ReadAll();
  30.     objFile.Close();
  31.     if (s.split(reg).length > 2) {
  32.         s = s.replace(reg, replacement);
  33.         fso.OpenTextFile(f + '.Log', 2, 1).Write(s);
  34.     }
  35. }
复制代码

TOP

回复 30# qixiaobin0715

可以在 goto :a 的上一行插入 endlocal

TOP

返回列表