Sử dụng C# để xem tập tin ẩn (hidden)

Ứng dụng console dùng để xem các tập tin ẩn trong một thư mục bất kỳ do người dùng nhập vào:

Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ReadHiddenFiles
{
class Program
{
static void Main(string[] args)
{
Console.Write(“Nhap duong dan den thu muc muon xem:”);
string duongdan = Console.ReadLine(); //nhập đường dẫn
DirectoryInfo di = new DirectoryInfo(duongdan); // khởi tạo đối tượng DirectoryInfo trỏ đến đường dẫn vừa nhập vào
FileInfo[] fi = di.GetFiles(); //khởi tạo mảng đối tượng FileInfo nhận lấy mảng các tập tin từ phương thức GetFiles()
foreach (FileInfo f in fi) // duyệt qua từng tập tin trong mảng tập tin FileInfo, nếu tập tin có thuộc tính ẩn thì mới in ra Full Name của nó
{
if (f.Attributes.ToString().Contains(FileAttributes.Hidden.ToString()))
Console.WriteLine(f.FullName);
}
}
}
}