博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
批处理通用测试代码
阅读量:6157 次
发布时间:2019-06-21

本文共 12259 字,大约阅读时间需要 40 分钟。

@echo off  setlocal enabledelayedexpansion  cd /d %~dp0  REM dir&pause  pushd "c:\"  dir/b c:  dir c:\lks是j.bat&&set panduan=1||set panduan=0          echo !panduan!&pause          echo errorlevel为:%errorlevel%&pause  if %ERRORLEVEL% == 0 (能找到文档) else echo 找不到文档  ::================代码区====取文件名==============  REM dir *.txt  REM for /f "delims=" %%i in (12.txt) do (  REM if not defined %%i echo %%~nxi  REM set %%i=任何值  REM )>>111.txt  ::================代码区==================  echo 完成!&pause&exit/b      批处理经典语句  dir /b/s|findstr /irc:"c:\\bb\\[^\\]*\.[^\\]*"

BAT+JS

@set @n=0;//&pushd c:\bb&dir /b C:\bb\*.txt|cscript -nologo -e:jscript "%~0" &echo.成功!& pause&exit/b  fso = new ActiveXObject("Scripting.FileSystemObject");  while (!WSH.StdIn.AtEndOfStream) {      f = WSH.StdIn.ReadLine();      txt = fso.OpenTextFile(f,1).ReadAll();      //*------------------以下为核心代码------------------*  txt=txt.replace(/.*(\/\/[^\/\s]+).*(\/\/[^\/\s]+).*$/mg,"$1\r\n$2");  //txt=txt.replace(/.*(\/\/[^\/\s]+)/mg,"$1\r\n");      //*-------------------------------------------------*      fso.OpenTextFile(f,2).Write(txt);  }

Bat+JS调试:

 

@if (0)==(0) echo off  rem -----------------------------  pushd C:\lishi  dir /b *次-*.txt>c:\12.txt  REM pushd C:\12  REM dir /ad /s /b >c:\12.txt  cscript /nologo /e:jscript %0   rem -----------------------------  rem dir /ad /s /b C:\12| cscript /nologo /e:jscript %0   pause&exit/b  @end    /*------------------注释部分--------------ME-------------------  @set @n=0 /* & echo off  pushd c:\12  REM cscript -nologo -e:jscript "%~0"
nul&exit/b @set @n=0;//&pushd c:\12&dir /b C:\12\*.txt|cscript -nologo -e:jscript "%~0" &echo.成功!& pause&exit/b ---------------- '&cls & echo off&pushd c:\12\2&dir /a/b/s|cscript /nologo /e:vbs %0 &pause & exit/b do until WSH.stdin.atendofstream f=WSH.stdin.readline() aa=CreateObject("wscript.shell").popup(f,0,"123",1) if (aa=2) then WSH.quit loop ------------------注释部分--------------------------------- */ //var text = WScript.StdIn.ReadAll().toLowerCase()//替换为下面几句: ///*-----------------单步调试模拟语句---------------------------- var cm=new Command()//加入的调试语句 var fso = new ActiveXObject("Scripting.FileSystemObject")//加入的调试语句 //--------------------------------------------------------------*/ function sortNumber(a, b){
return b.split(" ")[0] - a.split(" ")[0]}; var re = /^(\d+).*/mg; arr = s.replace(re, function($0,$1) {
return $1 + " " + $0;}); cm.set.p(arr)//加入的调试语句 arr = arr.split("\n"); arr.sort(sortNumber); cm.set.p(arr.join("\n"))//加入的调试语句 arr[n].replace(/^\d+ /mg, ""); //--------------------------------------------------------------*/ var ar = text.split(/\r\n/).sort() for(var i=ar.length-1;i--;){ cm.echo(ar[i+1])//加入的调试语句 cm.set.p(ar[i])//加入的调试语句 cm.echo('原始长度'+ar.length)//加入的调试语句 if(ar[i+1].indexOf(ar[i])==0){ar.splice(i,1)} cm.set.p('新的长度'+ar.length)//加入的调试语句 } text = ar.join('\r\n') WScript.Echo(text) //---------这个才是真正起作用的函数体-------------------* function Command(){ this.echo = function (str){WScript.Echo(str)} this.exit = function (num){WScript.Quit(num)} this.set = { p:function (str){ WScript.StdOut.Write(str) WScript.Echo("\n请按回车键继续...") return WScript.StdIn.ReadLine() } } } ///*-----------------单步调试模块---------------------------- function Command001(){ this.echo = function (str){WScript.Echo(str)} this.exit = function (num){WScript.Quit(num)} this.set = { a:function (str){eval(str)}, p:function (str){ WScript.StdOut.Write(str) WScript.Echo("\n请按回车键继续...") return WScript.StdIn.ReadLine() } } } ///*-----------------单步调试模块---------------------------- WScript.Quit()//这后面可随意添加调试性语句; WScript.Echo(text) WScript.Quit()//这后面可随意添加调试性语句; sdafsdaf sdfasdf.sdfl @if (0)==(0) echo off cscript /nologo /e:jscript %0 pause&exit/b @end var c=new Command() var fso = new ActiveXObject("Scripting.FileSystemObject") txt = fso.OpenTextFile("C:\\12.txt",1).ReadAll() //c.set.p(txt) //c.exit(1) var ar = txt.split(/\r\n/).sort() arr=fso.OpenTextFile("C:\\12.txt",1).Readline().split("\\"); for(var i=ar.length-1;i--;){ c.set.p(ar[i]) c.set.p(arr[i]) } /*--------------------------------- 12内容: C:\12\1 C:\12\2 C:\12\RibbonX C:\12\RibbonX\AddinInstance C:\12\RibbonX\AddinInstance\模块 C:\12\RibbonX\AddinInstance\资源文件 -----------------------------------------*/ @if (0)==(0) echo off rem ----------------------------- pushd C:\12\2\111 dir /b *.txt>c:\12.txt REM pushd C:\12 REM dir /ad /s /b >c:\12.txt cscript /nologo /e:jscript %0 rem ----------------------------- rem dir /ad /s /b C:\12| cscript /nologo /e:jscript %0 pause&exit/b @end var str="" var f var ss var sf //var text = WScript.StdIn.ReadAll().toLowerCase()//替换为下面几句: ///*-----------------单步调试模拟语句---------------------------- var cm=new Command()//加入的调试语句 var fso = new ActiveXObject("Scripting.FileSystemObject")//加入的调试语句 s = fso.OpenTextFile("C:\\12.txt",1).ReadAll()//加入的调试语句 f=fso.OpenTextFile("C:\\12.txt",1) //--------------------------------------------------------------*/ while (!f.AtEndOfStream) { ss=f.Readline(); // cm.set.p(ss) sf=fso.OpenTextFile(ss,1).ReadAll() str=str+sf+"\n" // cm.set.p(str) // cm.set.p("0000000000000000000") } cm.set.p(str) //--------------------------------------------------------------*/ //---------这个才是真正起作用的函数体-------------------* function Command(){ this.echo = function (str){WScript.Echo(str)} this.exit = function (num){WScript.Quit(num)} this.set = { p:function (str){ WScript.StdOut.Write(str) WScript.Echo("\n请按回车键继续...") return WScript.StdIn.ReadLine() } } } 最终:合并文本: @if (0)==(0) echo off pushd C:\12\2\111 dir /b *.txt |cscript /nologo /e:jscript %0 start "" "c:\zz.txt" pause&exit/b @end var str="" var fso = new ActiveXObject("Scripting.FileSystemObject") while (!WScript.StdIn.AtEndOfStream) { f = WScript.StdIn.ReadLine(); // cm.set.p(f) txt = fso.OpenTextFile(f).ReadAll(); str=str+txt+"\r\n" } fso.OpenTextFile("c:\\zz.txt", 2, true).Write(str) ================================================================= @echo off mshta "javascript:alert('sdf sdfsd sdfsdf');close()" REM mshta javascript:alert("Hello%%20%%20%%20wo%%20rld!!!") REM mshta "javascript:alert('!s!');close()" set "s=hello' "world" ' 'ABC" REM setlocal enabledelayedexpansion REM set "s=!s:'=\'!" REM mshta "javascript:alert('!s:"=\"!');close()" REM mshta vbscript:msgbox("12 345 6789")(close) REM mshta vbscript:createobject("Wscript.Shell").popup("123 456789")(close) REM mshta "javascript:var s=new ActiveXObject("Scripting.FileSystemObject").OpenTextFile("a0.txt",1).ReadAll();clipboardData.setData('text',s);close();" REM ws.run "mshta vbscript:clipboardData.SetData(""text"","""+s+""")(close)" REM ws.run "mshta vbscript:clipboardData.SetData(""text"","""+Replace(s,"$","""+vbCrLf+""")+""")(close)" 批处理获取选中文件路径 ::========================代码区===========================% for %%i in (%*) do ( echo %%i >>c:\tem set s=!s!%%~i## ) set s=!s: =@! mshta vbscript:clipboardData.SetData("text",replace(replace("!s!","##",vbcrlf),"@"," "))(close) ::==================代码区===========================% echo 操作已完成!按任意键退出!&pause>nul vbs获取选中文件路径 Set ws = CreateObject("WScript.Shell") s="" for each i in wscript.arguments s=s & """+vbcrlf+""" & i next REM wscript.echo s ws.run "mshta vbscript:clipboardData.SetData(""text"","""+s+""")(close)" REM ws.run "mshta vbscript:clipboardData.SetData(""text"","""+Replace(s,"$","""+vbCrLf+""")+""")(close)" REM ' 2>nul 3>nul&@echo off&cls REM '&start wscript.exe /nologo /e:vbs %0&exit REM createobject("sapi.spvoice").speak("ger lee shir joan gwaur DOS lieng merng") REM msgbox "这里是中国DOS联盟!",,"Welcome"

Bat+Js调试2

 

@set @n=0; /* & echo off  md "C:\12\2删除后的\" 2>nul  pushd "C:\12\1删除前的(原来的文件)\"  dir /b *.txt | cscript -nologo -e:jscript "%~0"  pause & exit/b & rem */      var cm=new Command()//加入的调试语句  fso = new ActiveXObject("Scripting.FileSystemObject");  while (!WScript.StdIn.AtEndOfStream) {      f = WScript.StdIn.ReadLine();  //  cm.set.p(f);WScript.Quit()///加入的调试语句      txt = fso.OpenTextFile(f).ReadAll();      cm.set.p(txt);WSH.quit()///加入的调试语句      txt = txt.replace(/[\s\S]*?( *前十名无限售条件股东)/, "$1");      txt = txt.replace(/ *前十大股东[\s\S]+(◆ *最新指标)/, "$1");      fso.OpenTextFile("..\\2删除后的\\"+f, 2, true).Write(txt);  }      ///*-----------------单步调试模块----------------------------  function Command(){          this.echo = function (str){WScript.Echo(str)}          this.exit = function (num){WScript.Quit(num)}          this.set = {                  a:function (str){eval(str)},                  p:function (str){                                  WScript.StdOut.Write(str)                                  WScript.Echo("\n请按回车键继续...")                                  return WScript.StdIn.ReadLine()                          }          }  }  ///*-----------------单步调试模块----------------------------  WScript.Quit()//这后面可随意添加调试性语句;  //--------------------------------------------------------------------------复杂调试版,搞出txt再弄;  @set @n=0; /* & echo off  md "C:\12\2删除后的\" 2>nul  pushd "C:\12\1删除前的(原来的文件)\"  dir /a-d/s /b >c:\12.txt  cscript -nologo -e:jscript "%~0"  REM dir /b *.txt | cscript -nologo -e:jscript "%~0"  pause & exit/b & rem */    fso = new ActiveXObject("Scripting.FileSystemObject");  ///*-----------------单步调试模拟语句----------------------------  var cm=new Command()//加入的调试语句  //var fso = new ActiveXObject("Scripting.FileSystemObject")//加入的调试语句  //text = fso.OpenTextFile("C:\\12.txt",1).ReadAll()//加入的调试语句  //cm.set.p(text)//加入的调试语句  //--------------------------------------------------------------*/  //while (!WScript.StdIn.AtEndOfStream) {  //    f = WScript.StdIn.ReadLine();  while (!fso.OpenTextFile("C:\\12.txt", 1).AtEndOfStream) {      f = fso.OpenTextFile("C:\\12.txt", 1).ReadLine();      cm.set.p(f)//加入的调试语句      txt = fso.OpenTextFile(f).ReadAll();      txt = txt.replace(/[\s\S]*?( *前十名无限售条件股东)/, "$1");      cm.set.p(txt)//加入的调试语句      txt = txt.replace(/ *前十大股东[\s\S]+(◆ *最新指标)/, "$1");      fso.OpenTextFile("..\\2删除后的\\"+f, 2, true).Write(txt);  }    ///*-----------------单步调试模块----------------------------  function Command(){          this.echo = function (str){WScript.Echo(str)}          this.exit = function (num){WScript.Quit(num)}          this.set = {                  a:function (str){eval(str)},                  p:function (str){                                  WScript.StdOut.Write(str)                                  WScript.Echo("\n请按回车键继续...")                                  return WScript.StdIn.ReadLine()                          }          }  }  ///*-----------------单步调试模块----------------------------  WScript.Quit()//这后面可随意添加调试性语句;

Bat+Js练习

 

@set @n=0;/* & echo off  pushd c:\12  cscript -nologo -e:jscript "%~0"
a00.txt pause & exit/b & rem */ var aa=new Me() //aa.e(1) //aa.msgbox("asdfsadfasdfsdafasddsfads") aa.m.a("asdfsadfasdfsdafasddsfads") txt=WScript.StdIn.readall() // new ActiveXObject("wscript.shell").popup(txt) arr=txt.split("\n") arr.sort(function(a,b){
return a.length-b.length}) msgbox(arr.join("\n")) function msgbox(str) { new ActiveXObject("wscript.shell").popup(str) } function Me() { this.e=function(str){WSH.Quit(str)} this.msgbox=function(str){
new ActiveXObject("wscript.shell").popup(str)} this.m={ a:function(str){ //a:function(str){
new ActiveXObject("wscript.shell").popup(str)} WScript.StdOut.Write(str) WScript.Echo("\n请按回车键继续...") } } }

 

转载于:https://www.cnblogs.com/zhanglei1371/p/6664876.html

你可能感兴趣的文章
集中管理系统--puppet
查看>>
分布式事务最终一致性常用方案
查看>>
Exchange 2013 PowerShell配置文件
查看>>
JavaAPI详解系列(1):String类(1)
查看>>
HTML条件注释判断IE<!--[if IE]><!--[if lt IE 9]>
查看>>
发布和逸出-构造过程中使this引用逸出
查看>>
使用SanLock建立简单的HA服务
查看>>
Subversion使用Redmine帐户验证简单应用、高级应用以及优化
查看>>
Javascript Ajax 异步请求
查看>>
DBCP连接池
查看>>
cannot run programing "db2"
查看>>
mysql做主从relay-log问题
查看>>
Docker镜像与容器命令
查看>>
批量删除oracle中以相同类型字母开头的表
查看>>
Java基础学习总结(4)——对象转型
查看>>
BZOJ3239Discrete Logging——BSGS
查看>>
SpringMVC权限管理
查看>>
spring 整合 redis 配置
查看>>
cacti分组发飞信模块开发
查看>>
浅析LUA中游戏脚本语言之魔兽世界
查看>>