Thursday, April 22, 2021

C# File System Path Members

using System;
using System.IO;

namespace Console_List_Folder_Files
{
    class Program
    {
        static void Main(string[] args)
        {
            string strFolderPath = @"C:\Users\AJEET\Desktop\Folder1";
            string[] files = Directory.GetFiles(strFolderPath);
            for (int i = 0; i < files.Length; i++)
            {
                //Console.WriteLine(files[i]); //returns full path
                //Console.WriteLine(Path.GetFileName( files[i])); //returns only file name with extension
                //Console.WriteLine(Path.GetFileNameWithoutExtension(files[i])); //returns file name without file extension
                //Console.WriteLine(Path.GetExtension( files[i])); //returns only file extension
                //Console.WriteLine(Path.GetDirectoryName( files[i])); //returns folder full path
                Console.WriteLine(Path.PathSeparator); //returns system specific path separator character
                
            }
            Console.Read();
        }
    }
}

OUTPUT:

;

No comments:

Post a Comment

Hot Topics