Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 18, 2015 00:01
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/a9a133ddaddead24062c to your computer and use it in GitHub Desktop.
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#.
// 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