Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 6, 2015 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/fdd350c60ad22764840a to your computer and use it in GitHub Desktop.
Save Fhernd/fdd350c60ad22764840a to your computer and use it in GitHub Desktop.
Proceso para copiar un archivo en lenguaje de programación C#.
// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
using System.IO;
namespace Receta.CSharp.R0503
{
public class CopiarArchivo
{
public static void Main()
{
Console.WriteLine();
// Rutas de origen y destino:
string origen = @"C:\etc\ArchivoTexto.txt";
string destino = @"C:\etc\CopiaArchivoTexto.txt";
FileInfo archivoOrigen = new FileInfo(origen);
FileInfo archivoDestino = new FileInfo(destino);
try
{
// Valida que el archivo `CopiaArchivoTexto.txt`:
if (File.Exists(destino))
{
archivoDestino.Delete();
}
// Copia el archivo `ArchivoTexto.txt`:
archivoOrigen.CopyTo(destino);
Console.WriteLine("{0} fue copiado en {1}.", origen, destino);
}
catch(IOException ioex)
{
Console.WriteLine(ioex.Message);
}
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment