我正在嘗試編寫一個帶有文本文件的腳本,並將其讀取以查找任何重複的值。下面的代碼將重複項寫入文本文件,並將重複項的值寫入文本文件。但是,我將如何在沒有任何重複值的情況下寫入值。如何在文本文件中找到重複項並將沒有重複項的值寫入文本文件?
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\A352592\Desktop\predata.txt",
ForReading)
Set objOutputFile = objFSO.OpenTextFile("C:\Users\A352592\Desktop
\Noduplicates.txt", 2, True)
Set objOutputFile2 = objFSO.OpenTextFile("C:\Users\A352592\Desktop
\Duplicates.txt", 2, True)
Set objOutputFile3 = objFSO.OpenTextFile("C:\Users\A352592\Desktop
\alone.txt", 2, True)
Set Dict = CreateObject("Scripting.Dictionary")
Do until objFile.atEndOfStream
strCurrentLine = objFile.ReadLine
If not Dict.Exists(strCurrentLine) then
objOutputFile.WriteLine strCurrentLine
Dict.Add strCurrentLine,strCurrentLine
ElseIf Dict.Exists(strCurrentLine) then
objOutputFile2.WriteLine strCurrentLine
Else
objOutputFile3.WriteLine strCurrentLine
End if
Loop
wscript.echo "Finished"