Home > Chỉ dẫn lập trình > Remove empty line and duplicate line (VBS)

Remove empty line and duplicate line (VBS)

//std_format.vbs

Set WshShell = CreateObject (“WScript.Shell”)
If Wscript.arguments.count <> 1 then Wscript.Quit
strFile = Wscript.arguments.Item(0)

Set objSet = CreateObject(“Scripting.Dictionary”)
Set objFSO = CreateObject(“scripting.filesystemobject”)
Set objTS = objFSO.OpenTextFile(strFile)
strFile2 = strFile & “.out”
Set objTS2 = objFSO.OpenTextFile(strFile2, 2, True, -2)

While Not objTS.AtEndOfStream
    strLine = objTS.ReadLine
    If strLine <> “” then
        On Error Resume Next
        Call objSet.Add (strLine, “value”)
        If Err = 0 Then
            objTs2.WriteLine(strLine)
            created = True
        End If
    End if
Wend
objTs.Close
objTs2.Close
Set objTs = Nothing
Set objTs2 = Nothing
objFSO.DeleteFile(strFile)
Call objFSO.MoveFile(strFile2, strFile)
Wscript.Echo “Done”

‘Then: Drag INPUT.DAT – Drop to std_format.vbs

Categories: Chỉ dẫn lập trình Tags:
  1. Chưa có bình luận nào.
Content (You can use Yahoo! Messenger Emoticons :D = smile)
Captcha