由于公司目前的数据比较乱,近期做系统优化,A系统中有1000个用户,B系统有1300个用户,但是A系统中的用户是正确的,B系统中的数据不正确,也有可能是用户数据没有及时做删除,所以想通过vbs脚本进行判断及删除,所以我们需要将A系统中的用户导出来,然后以A系统的数据为准,然后同时将B系统的用户信息也导出来,通过vbs比较,将不同的数据写入到新生成的文件中做处理,具体见下:
以下是一个例子:
A系统中导出的文件:
B系统导出的文件:
执行的效果应该是在新生成的文件中,将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
如果数据多的话,我们可以按照一下脚本试试
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
然后选择源文件-02
选择源文件-02之后,提示需要选择执行后的差异文件的路劲
执行成功
然后我们查看执行后的文件
转载于:https://blog.51cto.com/gaowenlong/1911226