I am trying to delete all rows from a .csv where a column is 0.
I use a streamreader to read the lines and then streamwriter to create a new file.
However the rows are not being deleted.
I only write certain columns to the new .csv file.
I use a streamreader to read the lines and then streamwriter to create a new file.
However the rows are not being deleted.
Code:
Dim SR As New StreamReader(extractPath & GebruikHierdieCSV & ".csv")
Dim SWriter As New StreamWriter(extractPath & "nuwe verkorte csv file.csv")
Dim strLineData() As String
Do While SR.Peek <> -1
strLineData = Split(SR.ReadLine, ",")
If strLineData(16) <> "0" Then
SWriter.WriteLine(strLineData(0) & "," & strLineData(1) & "," & strLineData(3) & "," & strLineData(6) & "," & strLineData(9) & "," & strLineData(10) & "," & strLineData(11) & "," & strLineData(13) & "," & strLineData(16) & "," & strLineData(18))
End If
Loop
SR.Close()
SWriter.Close()
MessageBox.Show("File has been created and can be located at " & extractPath & "nuwe verkorte csv file.csv")
I only write certain columns to the new .csv file.