Quantcast
Channel: How to change Unix Line feed to Windows Line Feed with C# - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to change Unix Line feed to Windows Line Feed with C#

$
0
0

I'm trying to write a unix2dos program to alter the line feeds of text files. The problem is instead of altering the contents of a text file, the file name was appended instead.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace unix2dos
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] filePaths = Directory.GetFiles(@"c:\textfiles\", "*.txt");

            foreach (string file in filePaths)
            {
                string[] lines = File.ReadAllLines(file);
                foreach (string line in lines)
                {
                    string replace = line.Replace("\n", "\r\n");
                    File.WriteAllText(file, replace);
                }
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>