بسبب خسارتي لبياناتي اكثر من مرة رأيت ان مشاركة ملفاتي الموجودة علي القرص الصلب أمراً صائبا لان ما كنت اشاركه هو الشيء المتبقي لذا ربما ستجدون مقالات من هذا النوع ومنها هذا المقال و الذي يحتوي علي كلاس فكرته موجوده في كتاب البرمجة الشيئية الذي امتحنت فيه قبل ايام.
الكلاس مكتوبة ب VB.Net و تبحث عن عدد الملفات الموجود في مكان معين باستخدام تاريخ الملفات او حجمها او امتداتها و الكود يفسر نفسه
Class CountFiles
'// Get Files Number in Specific Folder - License: Public Domain
Public Overloads Function GetFiles(ByVal Max As Integer, ByVal Min As Integer, ByVal PATH As String) As Integer
Max = Max * 1024 * 1024 'To Convert MB to Byte
Min = Min * 1024 * 1024 'To Convert MB to Byte
Dim files() As String
files = System.IO.Directory.GetFiles(PATH)
Dim i, counter As Integer
For i = 0 To UBound(files)
Dim F1 As New System.IO.FileInfo(files(i))
If F1.Length < Max And F1.Length > Min Then
counter += 1
End If
Next
Return (counter)
End Function
Public Overloads Function GetFiles(ByVal toDate As Date, ByVal FromDate As Date, ByVal PATH As String) As Integer
'To Get Files Nuumber By Date
Dim files() As String
files = System.IO.Directory.GetFiles(PATH)
Dim i, counter As Integer
For i = 0 To UBound(files)
Dim F1 As New System.IO.FileInfo(files(i))
If F1.CreationTime.Date < toDate And F1.CreationTime.Date > FromDate Then
counter += 1
End If
Next
Return (counter)
End Function
Public Overloads Function GetFiles(ByVal ext As String, ByVal PATH As String) As Integer
'To Get Files Nuumber By Extention
Dim files() As String
files = System.IO.Directory.GetFiles(PATH, "*." + ext)
Dim i, counter As Integer
For i = 0 To UBound(files)
counter += 1
Next
Return (counter)
End Function
End Class
للتاكد من عمل الكلاس
اكتب الكود الأتي في اي زر
Dim DllFiles As New CountFiles()
MsgBox(DllFiles.GetFiles("dll", "c:/windows"))
سيأتي لك بعدد الملفات ذات الأمتداد DLL في المجلد c:/windows
ارجو ان يستفاد شخص ما من هذه الفئة
.net, class, files, vb.net