UnixToDos Archivos C#
Publicado por Pedro A (1 intervención) el 30/03/2020 23:23:15
Buenas tardes como están, por si les sirve acá dejo un fragmento que código que obtiene un fichero de texto con formato Unix y lo transforma en Dos(ANSI) de salida en otra carpeta.
Saludos cordiales.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args )
{
DosToUnix(@"C:\exampleUnix.txt", @"C:\out\");
}
private static void DosToUnix(string rutaFileEntrada, string rutaFileSalida) {
string ruta = rutaFileEntrada;
string text = System.IO.File.ReadAllText(ruta, Encoding.GetEncoding(1252));
// Display the file contents to the console. Variable text is a string.
text = text.Replace("\n", "\r\n");
string nombreArchivo = Path.GetFileName(ruta);
string path = rutaFileSalida+nombreArchivo;
if (!File.Exists(path))
{
// Create a file to write to.
//using (StreamWriter sw = File.CreateText(path))
using (TextWriter tw = new StreamWriter(path.ToString(), true, Encoding.GetEncoding(1252)))
{
tw.WriteLine(text, Encoding.GetEncoding(1252));
}
}
}
}
}
Saludos cordiales.
Valora esta pregunta


0