清风细雨楼 Design By www.eepep.com
示例代码(t.vbs)如下:
复制代码 代码如下:
Set fso=Wscript.CreateObject("Scripting.FileSystemObject")
flrName="D:\Workspace\src\" 'dir that you need deal with
count=0 'get the count of modified files
function Traversal(dir)
set flr=fso.getfolder(dir)
set fs=flr.files
findstr1="[assembly: SecurityTransparent]" 'find string that need to be replaced
findstr2=replace(findstr1," ","") 'becasuse there is space char in findstr,so add this findstr2
replaceStr="[assembly: AllowPartiallyTrustedCallers()]" 'destination string in replace
for each f in fs
if lcase(f.name)="assemblyinfo.cs" then
set findf=fso.opentextfile(f)
do while findf.atendofstream=false
d=f.datelastmodified 'get modified datetime of current file
alltext=findf.readall
if(InStr(alltext,findstr1) > 0 ) then
s=replace(alltext,findstr1, replaceStr)
count=count+1
findf.close()
'If no findstr2, delete the following elseif block
elseif(InStr(alltext,findstr2) > 0) then
s=replace(alltext,findstr2, replaceStr)
count=count+1
findf.close()
else
findf.close()
exit do
end if
set r=fso.opentextfile(f, 2, true)
r.write s
d2=f.datelastmodified
if d2>=d then exit do
loop
end if
next
set fs=flr.subfolders
for each f in fs
Traversal(f.path)
next
end function
Traversal(flrName)
'msgbox ("Done! "& count & " files were modified successfully.")
wscript.echo "Done! "& count & " files were modified successfully." 'value popup by "wscript.echo" can be received by .bat easily
Wscript.quit count 'this variable "count" in order to get a return value by %ErrorLevel%
上面的操作只执行了处理文件的步骤
如果不需要提取运行结果,在批处理或主调vbs脚本里直接 运行该vbs文件就行了。
如果在bat 里调用该vbs脚本,并希望打印出提示信息
可以用下面的两种方法来实现:
1,在bat中加入如下代码
复制代码 代码如下:
@echo off
for /f "delims=" %%a in ('cscript //nologo c:\t.vbs') do (
set ScriptOut=%%a)
echo Result: %ScriptOut%
上面的 echo 打印字符串的格式自己根据需要定义,c:\t.vbs 文件目录修改为你的vbs文件目录。
2,bat 中加入
复制代码 代码如下:
@echo off
cscript //nologo c:\t.vbs
echo -----Modify %ErrorLevel% "AssemblyInfo.cs" files successfully.-----
上面echo 文本格式根据自己的需要定义 %ErrorLevel% 用来获取 上面示例vbs文件结尾 count的值,同样需要修改vbs文件的目录 c:\t.vbs
复制代码 代码如下:
Set fso=Wscript.CreateObject("Scripting.FileSystemObject")
flrName="D:\Workspace\src\" 'dir that you need deal with
count=0 'get the count of modified files
function Traversal(dir)
set flr=fso.getfolder(dir)
set fs=flr.files
findstr1="[assembly: SecurityTransparent]" 'find string that need to be replaced
findstr2=replace(findstr1," ","") 'becasuse there is space char in findstr,so add this findstr2
replaceStr="[assembly: AllowPartiallyTrustedCallers()]" 'destination string in replace
for each f in fs
if lcase(f.name)="assemblyinfo.cs" then
set findf=fso.opentextfile(f)
do while findf.atendofstream=false
d=f.datelastmodified 'get modified datetime of current file
alltext=findf.readall
if(InStr(alltext,findstr1) > 0 ) then
s=replace(alltext,findstr1, replaceStr)
count=count+1
findf.close()
'If no findstr2, delete the following elseif block
elseif(InStr(alltext,findstr2) > 0) then
s=replace(alltext,findstr2, replaceStr)
count=count+1
findf.close()
else
findf.close()
exit do
end if
set r=fso.opentextfile(f, 2, true)
r.write s
d2=f.datelastmodified
if d2>=d then exit do
loop
end if
next
set fs=flr.subfolders
for each f in fs
Traversal(f.path)
next
end function
Traversal(flrName)
'msgbox ("Done! "& count & " files were modified successfully.")
wscript.echo "Done! "& count & " files were modified successfully." 'value popup by "wscript.echo" can be received by .bat easily
Wscript.quit count 'this variable "count" in order to get a return value by %ErrorLevel%
上面的操作只执行了处理文件的步骤
如果不需要提取运行结果,在批处理或主调vbs脚本里直接 运行该vbs文件就行了。
如果在bat 里调用该vbs脚本,并希望打印出提示信息
可以用下面的两种方法来实现:
1,在bat中加入如下代码
复制代码 代码如下:
@echo off
for /f "delims=" %%a in ('cscript //nologo c:\t.vbs') do (
set ScriptOut=%%a)
echo Result: %ScriptOut%
上面的 echo 打印字符串的格式自己根据需要定义,c:\t.vbs 文件目录修改为你的vbs文件目录。
2,bat 中加入
复制代码 代码如下:
@echo off
cscript //nologo c:\t.vbs
echo -----Modify %ErrorLevel% "AssemblyInfo.cs" files successfully.-----
上面echo 文本格式根据自己的需要定义 %ErrorLevel% 用来获取 上面示例vbs文件结尾 count的值,同样需要修改vbs文件的目录 c:\t.vbs
清风细雨楼 Design By www.eepep.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
清风细雨楼 Design By www.eepep.com
暂无评论...
更新日志
2024年12月27日
2024年12月27日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]