change the known file extension using VBScript RRS feed

  • General discussion

  • Hi,

    I am converting one CSV file which contains 8 columns to another csv file. the new file contains 3rd and 5th column of soured file.

    I have done this by below code.

    Const ForWriting = 2
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("D:\source.csv")
    Set objLogFile = objFSO.CreateTextFile("D:\result.csv", _
        ForWriting, True)
    ' Write comma delimited list of columns in new CSV file.
    srcColumns = Split(objTextFile.ReadLine(), ",")
    extractedColumns = srcColumns(2) & "," & srcColumns(5)
    objLogFile.Write extractedColumns
    strLine = objTextFile.ReadLine
    MsgBox strLine
        Do While Not objTextFile.AtEndOfStream
        strLine = Split(objTextFile.ReadLine(), ",")
        objLogFile.Write strLine(2) & ","
        objLogFile.Write strLine(5)
        strWord = (strLine(2) & ",") & (strLine(5))
        MsgBox strWord

     But when opening the new csv file, the 2 data is stored in same cell with comma(,).

    So I tried to write in .txt file and change the file extension to .csv by Vbscript.

    so I want to store the data in separate column or change the new file's extension.

    Please give me any solution.


    • Changed type Bill_Stewart Friday, March 15, 2019 3:07 PM
    • Moved by Bill_Stewart Friday, March 15, 2019 3:07 PM This is not "fix/debug/rewrite my script for me" forum
    Wednesday, December 12, 2018 6:06 PM

All replies

  • Use PowerShell rather than VBScript - you can use Import-Csv and you don't need to worry about parsing.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 12, 2018 6:10 PM