fixing text files to DOS style line endings - CRLF

   edit
Follow


Today I ran into a project that had mixed line-ending styles between files in the project. There were even a few files that had different type of line endings within the same file (bulk of lines with UNIX style, and other bulks with DOS style)

 

I ended up running the following c# “script” to fix that, and set all files to UTF-8 while I was at it.

The trick is to simply load the file with File.ReadAllLines which is indifferent when it comes to the line-ending type, and then write that back using WriteAllLines which will use the currently set Environment.NewLine value (which is CRLF when on windows)

 

 

The code is listed here; you can simply download a zip, open it to the folder of your choice and dbl-click it.

the only prerequisite is .NET 4.0 (I wanted the recursive and lazy Directory.EnumerateFiles)

 

The is listed here. It is generated by a javascript snippet so if you cannot see this in your offline feed reader, just go to the gist page

 


     Tweet Follow @kenegozi