gunsmokingman Posted February 6, 2010 Share Posted February 6, 2010 I tested the scriptTest1.txt Operating System » Microsoft Windows 7 Ultimate 64-bit Os Version » 6.1.7600 Ultimate Edition Build Type » Multiprocessor Free Serial Number » 00426-292-0106894-85791 Processor Name » Intel(R) Core(TM)2 Quad CPU Q9300 @ 2.50GHz (x64) Video Card Name » NVIDIA GeForce 9800 GT Sound Device Name » C-Media PCI Audio Device Network Adapter » 802.11n Wireless PCI Express Card LAN Adapter Network Adapter » Realtek RTL8168C(P)/8111C(P) Family PCI-E Gigabit Ethernet NIC (NDIS 6.20)Test2.txt Computer Name » HOME-BETA-2008 Operating System » Microsoft Windows 7 Ultimate 64-bit Os Version » 6.1.7600 Ultimate Edition Build Type » Multiprocessor Free Serial Number » 00426-292-0106894-85791 Physical Memory » 8.00 GB Processor Name » Intel(R) Core(TM)2 Quad CPU Q9300 @ 2.50GHz (x64) Video Card Name » NVIDIA GeForce 9800 GT Sound Device Name » C-Media PCI Audio Device Network Adapter » 802.11n Wireless PCI Express Card LAN Adapter Network Adapter » Realtek RTL8168C(P)/8111C(P) Family PCI-E Gigabit Ethernet NIC (NDIS 6.20) Computer Type » KQ499AA-A2L m9360fDifferences.txt Computer Name » HOME-BETA-2008 Physical Memory » 8.00 GB Computer Type » KQ499AA-A2L m9360fSo the scripts looks for what missing in Test1, From Test2, reports it in Differences.txt Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") Dim StrTxt1, StrTxt2, StrTxt3, Ts'-> First Text File Set Ts = Fso.OpenTextFile("Test1.txt", 1) StrTxt1 = Ts.ReadAll Ts.Close'-> Second Text File Set Ts = Fso.OpenTextFile("Test2.txt", 1) Do Until Ts.AtEndOfStream StrTxt2 = Ts.ReadLine If InStr(StrTxt1, StrTxt2) = 0 Then StrTxt3 = StrTxt3 & StrTxt2 & vbCrLf End If Loop Ts.Close'-> Third Text File Set Ts = Fso.CreateTextFile("Differences.txt") Ts.WriteLine StrTxt3 Ts.Close Link to comment Share on other sites More sharing options...
bauxite Posted February 6, 2010 Author Share Posted February 6, 2010 (edited) yes you are right, in my attachment i have provided 2 files that dont work properly with the script, i think this is because of common "fragment" issues, something like that, however the bat works properly since its a line by line comparison although takes a year.anyway its not a huge deal.thanks again. Edited February 6, 2010 by bauxite Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 6, 2010 Share Posted February 6, 2010 The script only looks for what missing from one file, what you want is a script that looks for what missing from both files.I write up a script that will look for what missing from both files.1.txtXYZABCnotreallyuncommononlyin1.txtsodontreallymatter1onlyin1.txtsodontreallymatter2xyastring1astring2astring3DEpoiGVEND2.txtuncommonXYZuncommonstring2astring1astring2astring3ABuncommonstring3CDEiopVZnotreallyuncommonuncommonstring1ENDWhat missing from both files are stored Differences.txtABConlyin1.txtsodontreallymatter1onlyin1.txtsodontreallymatter2xyGVuncommonuncommonstring2ABuncommonstring3CVZuncommonstring1Save As Sort2.vbs Dim Dic :Set Dic = CreateObject("Scripting.Dictionary") Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") Dim Obj, Ts, Txt1 Set Ts = Fso.OpenTextFile("1.txt", 1) Do Until Ts.AtEndOfStream Txt1 = Ts.ReadLine Dic.Add Txt1 ,Txt1 Loop Ts.Close Set Ts = Fso.OpenTextFile("2.txt", 1) Do Until Ts.AtEndOfStream Txt1 = Ts.ReadLine If Not Dic.Exists(Txt1) Then Dic.Add Txt1 ,Txt1 Else Dic.Remove Txt1 End If Loop Ts.Close Set Ts = Fso.CreateTextFile("Differences.txt") For Each Obj In Dic.Keys Ts.WriteLine Obj Next Ts.Close Link to comment Share on other sites More sharing options...
bauxite Posted February 6, 2010 Author Share Posted February 6, 2010 Awesome.that is quite brilliant, thank you again Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 6, 2010 Share Posted February 6, 2010 Your welcome, now the only problem might be in the first loop change Do Until Ts.AtEndOfStream Txt1 = Ts.ReadLine Dic.Add Txt1 ,Txt1 LoopDictionary Objects can not have duplicate objects, so incase 1.txt has sayastring3astring3the script would error out because the object exists, this code change prevents that error Do Until Ts.AtEndOfStream Txt1 = Ts.ReadLine If Not Dic.Exists(Txt1) Then Dic.Add Txt1 ,Txt1 End If Loop Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now