سلام دوست عزیز

یکی از راه ها به این شکله ، البته نمیگم اصولی ترین راهه ولی کارتو راه میندازه.

ما یک کلاس ساده ایجاد میکنیم ، بعد یک لیست از اون کلاس درست میکنیم.

      public static List<_Folder_Properties> _Folder_List = new List<_Folder_Properties>();


public class _Folder_Properties
{
public string _Folder_Path = "";
public int _Folder_Count = 0;




public _Folder_Properties(string Folder_Path)
{
_Folder_Path = Folder_Path;


__Check_For_Folder_In_List(Folder_Path);


}




private void __Check_For_Folder_In_List(string _folder_name)
{


for (int i = 0; i < _Folder_List.Count; i++)
{
if (_Folder_List[i]._Folder_Path.ToLower().Contains(_folder_name.ToLo wer()) == true)
{
_Folder_List[i]._Folder_Count++; // increase folder counter
}
}


}




}

نحوه استفاده :

 _Folder_List.Add(new _Folder_Properties(@"D:\text.txt"));
_Folder_List.Add(new _Folder_Properties(@"D:\text.txt"));




MessageBox.Show(_Folder_List[0]._Folder_Path);
MessageBox.Show(_Folder_List[0]._Folder_Count.ToString());

فقط فراموش نشه در موقع بستن برنامه یا کلاس لیست رو خالی کنی چون اگر تعدا فایل ها زیاد باشه چند مگ حافظه میگیره:

  _Folder_List.Clear();
_Folder_List = null;