Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 17, 2015 19:11
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/88d740755482cd828d13 to your computer and use it in GitHub Desktop.
Save Fhernd/88d740755482cd828d13 to your computer and use it in GitHub Desktop.
Uso de la clase `Path` en C#.
// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
using System.IO;
namespace Receta.CSharp.R0512
{
public class ManipulacionRutas
{
public static void Main()
{
Console.WriteLine(Environment.NewLine);
string ruta1 = @"C:\etc\RecetasSerie5.txt";
string ruta2 = @"C:\etc\RecetasSerie5";
string ruta3 = @"etc";
// Valida que `ruta1` tiene extensión:
if (Path.HasExtension(ruta1))
{
Console.WriteLine("{0} cuenta con extensión.", ruta1);
}
// Valida que `ruta2` tiene extensión:
if (!Path.HasExtension(ruta2))
{
Console.WriteLine("{0} no cuenta con extensión.", ruta2);
}
// Valida que `ruta3` tiene información de ruta raíz (root):
if (!Path.IsPathRooted(ruta3))
{
Console.WriteLine("La ruta {0} no tiene información de ruta raíz (root).", ruta3);
}
Console.WriteLine();
Console.WriteLine("La ruta absoluta de {0} es {1}.", ruta3, Path.GetFullPath(ruta3));
Console.WriteLine(Environment.NewLine);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment