26-10-19, 07:32 PM
(آخر تعديل لهذه المشاركة : 27-10-19, 01:57 AM {2} بواسطة asemshahen5.)
السلام عليكم ورحمة الله وبركاته
ان شاء الله تعجبكم المكتبة
وللفائدة العلمية هذا سورس كود المكتبة كامل
والمثال مرفق
اقدم لكم مثال على برنامج للبحث عن الملفات في نظام الوندوز
البرنامج يحتوي على مكتبة dll صممتها لغرض البحث واسمها SearchFile
بالاساس هو المثال فقط لشرح المكتبة واضفت ميزة حلوة وهي البحث عن العناصر المكررة ومقارنتها مع بعضها واظهار نتيجة تطابق من 100
تحتوي المكتبة على 4 احداث وهي
(جلب عدد الملفات المراد البحث عنها)
(وضع البحث ويكون على شكل نص)
(انتهاء البحث)
(الملفات التي وجدت)
ان شاء الله تعجبكم المكتبة
وللفائدة العلمية هذا سورس كود المكتبة كامل
كود :
Imports System.Windows.Forms
Public Class Abody_SearchFile
Public Shared ObjectCount As Integer = 0
Dim Count As Integer = 0
Dim Dirc As New ArrayList
Dim t As String = ""
Dim num As Integer = 0
Public Sub New()
ObjectCount += 1
End Sub
#Region "Search"
Public Sub Search(ByVal paths() As String, ByVal word As String)
On Error Resume Next
Count = 0
Dirc.Clear()
GetDir(paths, word.ToLower)
Dim di = From a As String In Dirc
Search(di.ToArray)
End Sub
Public Sub Search(ByVal path As String, ByVal word As String)
On Error Resume Next
Count = 0
Dirc.Clear()
GetDir(path, word.ToLower)
Dim di = From a As String In Dirc
Search(di.ToArray)
End Sub
#End Region
#Region "DD"
Private Sub GetDir(ByVal paths() As String, ByVal t As String)
On Error Resume Next
Me.t = t.ToLower
For Each D As String In paths
Application.DoEvents()
If FindFile(D, t) Then
Dirc.Add(D)
End If
If IO.Directory.GetDirectories(D).Count > 0 Then
RaiseEvent SearchState(Me, "Wait for get files count...")
GetDir(IO.Directory.GetDirectories(D), t)
End If
Next
End Sub
Private Sub GetDir(ByVal path As String, ByVal t As String)
On Error Resume Next
Me.t = t
If FindFile(path, t) Then
Dirc.Add(path)
End If
If IO.Directory.GetDirectories(path).Count > 0 Then
RaiseEvent SearchState(Me, "Wait for get files count...")
GetDir(IO.Directory.GetDirectories(path), t)
End If
End Sub
#End Region
#Region "Property"
ReadOnly Property About() As String
Get
Return "3booody\\vb4arb.com"
End Get
End Property
#End Region
#Region "Function"
Private Function FindFile(ByVal path As String, ByVal t As String) As Boolean
Try
Dim ar = From a As String In IO.Directory.GetFiles(path) Where a.Contains(t)
If ar.Count > 0 Then
Return True
End If
Catch ex As Exception
End Try
Return False
End Function
#End Region
#Region "Event"
Event GetFilesCount(ByVal sender As Object, ByVal Count As Integer)
Event GetFiles(ByVal sender As Object, ByVal path As String)
Event SearchEnd(ByVal sender As Object, ByVal e As EventArgs)
Event SearchState(ByVal sender As Object, ByVal State As String)
#End Region
#Region "Search State"
Private Sub Search(ByVal paths() As String)
On Error Resume Next
If t = "" Then
For Each p As String In paths
Application.DoEvents()
Count += IO.Directory.GetFiles(p).Count
Next
Else
For Each p As String In paths
Application.DoEvents()
Dim ar = From a As String In IO.Directory.GetFiles(p) Where a.ToLower.Contains(t)
Count += ar.Count
Next
End If
If Count = 0 Then
RaiseEvent SearchState(Me, "Not Found any File")
RaiseEvent SearchEnd(Me, New EventArgs)
Return
End If
RaiseEvent GetFilesCount(Me, Count)
num = 0
For Each p As String In paths
Application.DoEvents()
Serch(p)
RaiseEvent SearchState(Me, "Searching for files")
Next
RaiseEvent SearchEnd(Me, New EventArgs)
RaiseEvent SearchState(Me, "Search finished")
End Sub
Private Sub Serch(ByVal path As String)
If t = "" Then
For Each file As String In IO.Directory.GetFiles(path)
Application.DoEvents()
RaiseEvent GetFiles(Me, file)
If num = Count Then
RaiseEvent SearchEnd(Me, New EventArgs)
Else
num += 1
End If
Next
Else
For Each file As String In IO.Directory.GetFiles(path)
If file.ToLower.Contains(t) Then
Application.DoEvents()
RaiseEvent GetFiles(Me, file)
If num = Count Then
RaiseEvent SearchEnd(Me, New EventArgs)
Else
num += 1
End If
End If
Next
End If
End Sub
#End Region
End Class
والمثال مرفق