聪明文档网

聪明文档网

最新最全的文档下载
当前位置: 首页> 正在进行安全检测...

正在进行安全检测...

时间:2023-10-20 22:46:31    下载该word文档
vbs批量修改文件,bat批处理文件调用执行vbs并在cmd窗口打印返回值vbs运行结果)使用vbs脚本对工作目录下的字符串进行替换并统计被修改的文件数主调的批处理方法将捕捉该vbs脚本运行后的结果并打印在cmd窗口。示例代码(t.vbs)如下:Setfso=Wscript.CreateObject("Scripting.FileSystemObject"flrName="D:\Workspace\src\"'dirthatyouneeddealwithcount=0'getthecountofmodifiedfilesfunctionTraversal(dirsetflr=fso.getfolder(dirsetfs=flr.filesfindstr1="[assembly:SecurityTransparent]"'findstringthatneedtobereplacedfindstr2=replace(findstr1,"",""'becasusethereisspacecharinfindstr,soaddthisfindstr2replaceStr="[assembly:AllowPartiallyTrustedCallers(]"'destinationstringinreplaceforeachfinfsiflcase(f.name="assemblyinfo.cs"thensetfindf=fso.opentextfile(fdowhilefindf.atendofstream=falsed=f.datelastmodified'getmodifieddatetimeofcurrentfilealltext=findf.readallif(InStr(alltext,findstr1>0thens=replace(alltext,findstr1,replaceStrcount=count+1findf.close('Ifnofindstr2,deletethefollowingelseifblockelseif(InStr(alltext,findstr2>0thens=replace(alltext,findstr2,replaceStrcount=count+1findf.close(elsefindf.close(exitdoendifsetr=fso.opentextfile(f,2,truer.writesd2=f.datelastmodifiedifd2>=dthenexitdoloopendifnextsetfs=flr.subfolders
foreachfinfsTraversal(f.pathnextendfunctionTraversal(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=%%aechoResult:%ScriptOut%上面的echo打印字符串的格式自己根据需要定义,c:\t.vbs文件目录修改为你的vbs文件目录。2bat中加入@echooffcscript//nologoc:\t.vbsecho-----Modify%ErrorLevel%"AssemblyInfo.cs"filessuccessfully.-----上面echo文本格式根据自己的需要定义%ErrorLevel%用来获取上面示例vbs文件结尾count的值,同样需要修改vbs文件的目录c:\t.vbs

免费下载 Word文档免费下载: 正在进行安全检测...

  • 29.8

    ¥45 每天只需1.0元
    1个月 推荐
  • 9.9

    ¥15
    1天
  • 59.8

    ¥90
    3个月

选择支付方式

  • 微信付款
郑重提醒:支付后,系统自动为您完成注册

请使用微信扫码支付(元)

订单号:
支付后,系统自动为您完成注册
遇到问题请联系 在线客服

常用手机号:
用于找回密码
图片验证码:
看不清?点击更换
短信验证码:
新密码:
 
绑定后可用手机号登录
请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系 在线客服