VBS Script Browse For A Text File And Remove Duplicates Entries From It

 

This VBS Script will allow you to browse for a text file and will remove or strip all of the duplicates from it and then rewrite the original text file.

 

VBS Script:

 

Const ForReading = 1

Const ForWriting = 2

 

Set objDialog = CreateObject("UserAccounts.CommonDialog")

objDialog.Filter = "Text Files|*.Txt"

intResult = objDialog.ShowOpen

If intResult = 0 Then

Wscript.Quit

Else

strFileName = objDialog.FileName

End If

 

Set objDictionary = CreateObject("Scripting.Dictionary")

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

 

Do Until objFile.AtEndOfStream

strName = objFile.ReadLine

If Not objDictionary.Exists(strName) Then

objDictionary.Add strName, strName

End If

Loop

objFile.Close

 

Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)

For Each strKey in objDictionary.Keys

objFile.WriteLine strKey

Next

 

objFile.Close

MsgBox "Done"

 

 

 

Published Sunday, September 28, 2008 1:51 PM by dhite
Filed under:

Comments

No Comments