Manipulate Strings Representing File Names - CSharp File IO

CSharp examples for File IO:Path

Description

Manipulate Strings Representing File Names

Demo Code


using System;//from   w  w w  .  j a v a 2s.c om
using System.IO;

    static class MainClass
    {
        static void Main(string[] args)
        {
            string filename;
            filename = @"..\System\MyFile.txt";
            filename = Path.GetFileName(filename);

            Console.WriteLine(filename);

            filename = @"..\..\myfile.txt";
            string fullPath = @"c:\Temp";

            filename = Path.GetFileName(filename);
            fullPath = Path.Combine(fullPath, filename);

            Console.WriteLine(fullPath);
            Console.WriteLine(filename);

            // (fullPath is now "c:\Temp\myfile.txt")

        }
    }

Result


Related Tutorials