您现在的位置是:首页 > 文章详情

VBS脚本判断及获取两个文件之间的不同内容

日期:2017-03-28点击:440

由于公司目前的数据比较乱,近期做系统优化,A系统中有1000个用户,B系统有1300个用户,但是A系统中的用户是正确的,B系统中的数据不正确,也有可能是用户数据没有及时做删除,所以想通过vbs脚本进行判断及删除,所以我们需要将A系统中的用户导出来,然后以A系统的数据为准,然后同时将B系统的用户信息也导出来,通过vbs比较,将不同的数据写入到新生成的文件中做处理,具体见下:

以下是一个例子:

A系统中导出的文件:

p_w_picpath

B系统导出的文件:

p_w_picpath

执行的效果应该是在新生成的文件中,将B系统文件中的user06、user07写入到新的文件中就正常了;

因为:A系统的数据是准确的,所以通过比对后,将差异数据写入到新的数据文件中;

Dim Txt1,Txt2,Txt3 msgbox "请选择源文件-01" Txt1 = CreateObject("WScript.Shell").Exec("mshta vbscript:""<input type=file id=f><script>f.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(f.value)[close()];</script>""").StdOut.ReadAll msgbox "请选择源文件-02" Txt2 = CreateObject("WScript.Shell").Exec("mshta vbscript:""<input type=file id=f><script>f.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(f.value)[close()];</script>""").StdOut.ReadAll msgbox "请选择保存路劲" Txt3 = BrowseForFolder("txt3 fold: ") & "\zhixing.txt" Set dic = CreateObject("scripting.dictionary") Set fso = CreateObject("scripting.filesystemobject") Set of1 = fso.OpenTextFile(Txt1) Do While of1.AtEndOfLine <> True dic.Add of1.ReadLine,1 Loop Set of2 = fso.OpenTextFile(Txt2) Set of3 = fso.CreateTextFile(Txt3) Do While of2.AtEndOfLine <> True line = of2.ReadLine If Not dic.Exists(line) Then of3.Writeline line End If Loop msgbox "ok" Function BrowseForFolder(ByVal strTips)   Dim objFolder   Set objFolder = CreateObject("Shell.Application").BrowseForFolder (&H0, strTips, &H0010 + &H0001)   If (Not objFolder Is Nothing) Then BrowseForFolder = objFolder.Self.Path  'objFolder.Items().Item().Path End Function

p_w_picpath

如果数据多的话,我们可以按照一下脚本试试

Dim Txt1,Txt2,Txt3 msgbox "请选择源文件-01" Txt1 = CreateObject("WScript.Shell").Exec("mshta vbscript:""<input type=file id=f><script>f.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(f.value)[close()];</script>""").StdOut.ReadAll msgbox "请选择源文件-02" Txt2 = CreateObject("WScript.Shell").Exec("mshta vbscript:""<input type=file id=f><script>f.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(f.value)[close()];</script>""").StdOut.ReadAll msgbox "请选择保存路劲" Txt3 = BrowseForFolder("txt3 fold: ") & "\zhixing.txt" Set dic = CreateObject("scripting.dictionary") Set fso = CreateObject("scripting.filesystemobject") Set of1 = fso.OpenTextFile(Txt1,1) Do While Not of1.atendofstream   line = of1.ReadLine If Not dic.Exists(line) Then dic.Add line,1 End if Loop Set of2 = fso.OpenTextFile(Txt2,1) Set of3 = fso.CreateTextFile(Txt3) Do While Not of2.atendofstream   lined = of2.ReadLine If Not dic.Exists(lined) Then of3.Writeline lined End If Loop Function BrowseForFolder(ByVal strTips)   Dim objFolder   Set objFolder = CreateObject("Shell.Application").BrowseForFolder (&H0, strTips, &H0010 + &H0001)   If (Not objFolder Is Nothing) Then BrowseForFolder = objFolder.Self.Path  'objFolder.Items().Item().Path End Function msgbox "ok"

开始执行,需要选择源文件-01

p_w_picpath

p_w_picpath

然后选择源文件-02

p_w_picpath

选择源文件-02之后,提示需要选择执行后的差异文件的路劲

p_w_picpath

p_w_picpath

执行成功

p_w_picpath

然后我们查看执行后的文件

p_w_picpath

p_w_picpath

原文链接:https://blog.51cto.com/gaowenlong/1911226
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章