Computer >> Máy Tính >  >> Lập trình >> C#

C # Chương trình hiển thị tên của thư mục

Đầu tiên, sử dụng DirectoryInfo hoạt động trên Thư mục. Tham số được đặt trong đó là đường dẫn tệp -

DirectoryInfo dir = new DirectoryInfo(@"D:\new\");

Để lấy tên của thư mục, hãy sử dụng thuộc tính Name -

dir.Name

Sau đây là mã để hiển thị tên của thư mục -

Ví dụ

using System.IO;
using System;
public class Program {
   public static void Main() {
      DirectoryInfo dir = new DirectoryInfo(@"D:\new\");
      // displaying the name of the directory
      Console.WriteLine(dir.Name);
   }
}

Đầu ra

D:\new\