@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"<a.txt cscript -nologo -e:jscript "%~0" pause & exit/b & rem */ //new ActiveXObject("Wscript.shell").popup(WScript.StdIn.readall()) var s=new me() var fso=new ActiveXObject("scripting.filesystemobject") var txt=fso.opentextfile("c:\\12\\a.txt").readall() s.a.b(txt) s.a.b("asdfbc") function me() { var fso=new ActiveXObject("scripting.filesystemobject") this.fso= { r:function(str){fso.opentextfile(str).readall()}} this.a= {b:function(str){ WSH.stdout.write(str) WSH.echo("\n按回车继续。。。") WSH.stdin.readline() } } } //------------------注释部分--------------ME------------------- 我的js+bat感悟 @set @n=0 /* & echo off pushd c:\12 dir /a/b/s c:\12|cscript -nologo -e:jscript "%~0" pause & exit/b & rem */ rem可去掉 var n=0,m=0 var ws=new ActiveXObject("wscript.shell") var fso=new ActiveXObject("scripting.filesystemobject") while (!WSH.stdin.atendofstream){ //此处while第一个字母w必须是小写!而WSH,WScript的WSH和WS必须是大写! f=WSH.stdin.readline() n++; m=m+1; var aa=ws.popup(f,0,"消息",1) // ws.popup("aa的值为:"+aa) if (aa==2){ ws.popup("将退出!") WScript.echo("m和n的值为:"+m+"和"+n) WSH.quit() } } @if (0)==(0) echo off cscript /nologo /e:jscript %0 pause& exit/b @end '&cls&dir/a-d/b/s C:\12\*.txt | cscript -nologo -e:vbscript "%~0" &echo 操作已完成!按任意键退出!&pause>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"<a.txt>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请按回车键继续...") } } }