Created
July 6, 2015 15:27
-
-
Save Fhernd/fdd350c60ad22764840a to your computer and use it in GitHub Desktop.
Proceso para copiar un archivo en lenguaje de programación C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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