In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "vbs how to achieve batch modification of files", in the daily operation, I believe that many people have doubts about how to achieve batch modification of files in vbs. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve batch modification of files by vbs". Next, please follow the editor to study!
The sample code (t.vbs) is as follows:
The copy code is as follows:
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%
The above operation only performs the steps of processing the file
If you don't need to extract the run results, just run the vbs file directly in a batch or main vbs script.
If you call the vbs script in bat and want to print out a prompt
You can do this in two ways:
1, add the following code to bat
The copy code is as follows:
@ echo off
For / f "delims="% an in ('cscript / / nologo c:\ t.vbs') do (
Set ScriptOut=%%a)
Echo Result:% ScriptOut%
The format of the above echo print string is defined as needed, and the c:\ t.vbs file directory is changed to your vbs file directory.
2. Add to the bat
The copy code is as follows:
@ echo off
Cscript / / nologo c:\ t.vbs
Echo-Modify% ErrorLevel% "AssemblyInfo.cs" files successfully.-
The above echo text format defines% ErrorLevel% to get the value of count at the end of the above example vbs file according to your own needs. You also need to modify the directory c:\ t.vbs of the vbs file.
At this point, the study of "how to modify files in batch by vbs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.