预览加载中,请您耐心等待几秒...
1/2
2/2

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

vbs批量修改文件,bat批处理文件调用执行vbs,并在cmd窗口打印返回值〔vbs运行结果〕使用vbs脚本对工作目录下的字符串进行替换并统计被修改的文件数主调的批处理方法将捕捉该vbs脚本运行后的结果并打印在例如代码〔t.vbs〕如下:cmd窗口。Setfso=Wscript.CreateObject("Scripting.FileSystemObject")flrName="D:\Workspace\src\"'dirthatyouneeddealwithcount=0'getthecountofmodifiedfilesfunctionTraversal(dir)setflr=fso.getfolder(dir)setfs=flr.filesfindstr1="[assembly:SecurityTransparent]"'findstringthatneedtobereplacedfindstr2=replace(findstr1,"","")'becasusethereisspacecharinfindstr,soaddthisfindstr2replaceStr="[assembly:replaceAllowPartiallyTrustedCallers()]"'destinationstringinforeachfinfsiflcase(f.name)="assemblyinfo.cs"thensetfindf=fso.opentextfile(f)dowhilefindf.atendofstream=falsed=f.datelastmodified'getmodifieddatetimeofcurrentfilealltext=findf.readallif(InStr(alltext,findstr1)>0)thens=replace(alltext,findstr1,replaceStr)count=count+1findf.close()'Ifnofindstr2,deletethefollowingelseifblockelseif(InStr(alltext,findstr2)>0)thens=replace(alltext,findstr2,replaceStr)count=count+1findf.close()elsefindf.close()exitdoendifsetr=fso.opentextfile(f,2,true)r.writesd2=f.datelastmodifiedifd2>=dthenexitdoloopendifnextsetfs=flr.subfoldersforeachfinfsTraversal(f.path)nextendfunctionTraversal(flrName)'msgbox("Done!"&count&"filesweremodifiedsuccessfully.")wscript.echo"Done!"&count&"filesweremodifiedsuccessfully."'valuepopupby"wscript.echo"canbereceivedby.bateasilyWscript.quitcount'thisvariable"count"inordertogetareturnvalueby%ErrorLevel%上面的操作只执行了处理文件的步骤如果不需要提取运行结果,在批处理或主调vbs脚本里直接运行该vbs文件就行了。如果在bat里调用该vbs脚本,并希望打印出提示信息可以用下面的两种方法来实现:1,在bat中加入如下代码echoofffor/f"delims="%%ain('cscript//nologoc:\t.vbs')do(setScriptOut=%%a)echoResult:%ScriptOut%上面的echo打印字符串的格式自己根据需要定义,c:\t.vbs文件目录修改为你的vbs文件目录。2,bat中加入echooffcscript//nologoc:\t.vbsecho-----Modify%ErrorLevel%"AssemblyInfo.cs"filessuccessfully.-----