Created
July 18, 2015 00:01
-
-
Save Fhernd/a9a133ddaddead24062c to your computer and use it in GitHub Desktop.
Comprobación si una ruta es un directorio o un archivo en 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.R0513 | |
{ | |
public class ComprobacionRutas | |
{ | |
public static void Main(String[] rutas) | |
{ | |
Console.WriteLine(Environment.NewLine); | |
// Por cada argumento pasado desde la línea de comandos | |
// se determina si es un directorio o un archivo: | |
foreach (string ruta in rutas) | |
{ | |
Console.Write ("{0}", ruta); | |
if (Directory.Exists(ruta)) | |
{ | |
Console.WriteLine(" es un directorio."); | |
} | |
else if (File.Exists(ruta)) | |
{ | |
Console.WriteLine(" es un archivo."); | |
} | |
else | |
{ | |
Console.WriteLine(" no existe."); | |
} | |
} | |
Console.WriteLine(Environment.NewLine); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment