Created
July 17, 2015 19:11
-
-
Save Fhernd/88d740755482cd828d13 to your computer and use it in GitHub Desktop.
Uso de la clase `Path` 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.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