Converting *nix files to Win text files

I don’t know why it took me so long to do this.  I regularly download files, only to open them up to see that they were created on a *nix computer.  That means it uses CR to symbolize the end of a line rather than CRLF, which is the common end of line on a Windows system.  As part of another project that I am working on, I downloaded a huge archive of spam and regular email.  The only problem was all of the files used CR instead of CRLF.  That, and they didn’t have an extension, so I had to choose each time to open it with Notepad.

So I went into VB.Net, and made a quick and dirty form that recursively looked at each subfolder and converted each file.  As part of the conversion, it was changed to a .txt file, and the original was deleted.

Here is the code to do that:

Private Sub ConvertFile(ByVal fi As FileInfo)
  If fi.Extension = ".txt" Then Return

  Dim r As New FileStream(fi.FullName, FileMode.Open)
  Dim d As New StreamReader(r)
  Dim s As New FileStream(fi.FullName & ".txt", FileMode.Create)
  Dim w As New StreamWriter(s)
  Dim str As String = ""
  Do While Not d.EndOfStream
    w.WriteLine(d.ReadLine)
  Loop
  d.Close()
  r.Close()
  fi.Delete()
  w.Flush()
  w.Close()
  s.Close()
  _fileCount += 1
  lblOutput.Text = "Converted " & _fileCount & " files."
  Application.DoEvents()
End Sub

Hopefully this will help anyone having the same type of frustrations.