国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

vbs 批量修改文件,bat 批處理文件調(diào)用執(zhí)行vbs,并在cmd窗口打印

2019-10-26 18:05:04
字體:
供稿:網(wǎng)友
示例代碼(t.vbs)如下:
復(fù)制代碼 代碼如下:

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%

上面的操作只執(zhí)行了處理文件的步驟
如果不需要提取運行結(jié)果,在批處理或主調(diào)vbs腳本里直接 運行該vbs文件就行了。

如果在bat 里調(diào)用該vbs腳本,并希望打印出提示信息
可以用下面的兩種方法來實現(xiàn):
1,在bat中加入如下代碼
復(fù)制代碼 代碼如下:

@echo off
for /f "delims=" %%a in ('cscript //nologo c:/t.vbs') do (
set ScriptOut=%%a)
echo Result: %ScriptOut%

上面的 echo 打印字符串的格式自己根據(jù)需要定義,c:/t.vbs 文件目錄修改為你的vbs文件目錄。

2,bat 中加入
復(fù)制代碼 代碼如下:

@echo off
cscript //nologo c:/t.vbs
echo -----Modify %ErrorLevel% "AssemblyInfo.cs" files successfully.-----

上面echo 文本格式根據(jù)自己的需要定義 %ErrorLevel% 用來獲取 上面示例vbs文件結(jié)尾 count的值,同樣需要修改vbs文件的目錄 c:/t.vbs

您可能感興趣的文章:

解決Java調(diào)用BAT批處理不彈出cmd窗口的方法分析運行bat時隱藏cmd窗口的方法(bat隱藏窗口 隱藏運行bat文件)使用bat打開多個cmd窗口執(zhí)行g(shù)ulp、node
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 贡嘎县| 南皮县| 峡江县| 峡江县| 社旗县| 玉环县| 女性| 盐亭县| 如东县| 澄江县| 武夷山市| 城市| 扶风县| 中西区| 安泽县| 顺昌县| 定远县| 綦江县| 兰考县| 凉城县| 抚顺市| 山西省| 湄潭县| 临夏县| 南通市| 天镇县| 丰顺县| 蒙城县| 平潭县| 喜德县| 永年县| 沾化县| 文山县| 阜新| 建昌县| 盐津县| 黑水县| 太谷县| 鞍山市| 岑溪市| 保定市|