Advertisement
Fhernd

CopiarArchivo.cs

Jul 6th, 2015
1,353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. // OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. using System;
  4. using System.IO;
  5.  
  6. namespace Receta.CSharp.R0503
  7. {
  8.     public class CopiarArchivo
  9.     {
  10.         public static void Main()
  11.         {
  12.             Console.WriteLine();
  13.            
  14.             // Rutas de origen y destino:
  15.             string origen = @"C:\etc\ArchivoTexto.txt";
  16.             string destino = @"C:\etc\CopiaArchivoTexto.txt";
  17.            
  18.             FileInfo archivoOrigen = new FileInfo(origen);
  19.             FileInfo archivoDestino = new FileInfo(destino);
  20.            
  21.             try
  22.             {
  23.                 // Valida que el archivo `CopiaArchivoTexto.txt`:
  24.                 if (File.Exists(destino))
  25.                 {
  26.                     archivoDestino.Delete();
  27.                 }
  28.                
  29.                 // Copia el archivo `ArchivoTexto.txt`:
  30.                 archivoOrigen.CopyTo(destino);
  31.                 Console.WriteLine("{0} fue copiado en {1}.", origen, destino);
  32.             }
  33.             catch(IOException ioex)
  34.             {
  35.                 Console.WriteLine(ioex.Message);
  36.             }
  37.            
  38.             Console.WriteLine();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement