Dosya Arama Örneği
#1
*** 12/10/2009 revizyon gördü.***

Merhaba,

Office 2007 uygulamalarından kaldırılan "FileSearch" fonksiyonu önceki versiyonlarda mevcuttu.
İhtiyaç olabileceği düşüncesiyle gayet kısa kod yapısıyla hazırladığım bu çalışmayı sizlerle de paylaşmak istiyorum.

Bu dosyanın oluşmasında katkısı bulunan değerli dostum Taruz' a da teşekkürlerimi sunarım.

[Resim: filesearch.jpg]

Visual Basic
  1. Private Sub Komut2_Click()
  2. On Error GoTo hata
  3. Dim klasor As Object, yol As String
  4.  
  5. Set klasor = CreateObject("Shell.Application").BrowseForFolder _
  6. (0, "Lütfen bir klasor seçin !", 1)
  7. If klasor Is Nothing Then Exit Sub
  8. yol = klasor.Items.Item.Path
  9. ListBox1.RowSource = ""
  10.  
  11. With Label1
  12. .Visible = True
  13. .Caption = "Bulunuyor..."
  14. End With
  15.  
  16. ListBox1.RowSource = ""
  17. Liste (yol)
  18. AltListe (yol)
  19. Label1.Caption = "Bitti ! Toplam : " & FormatNumber(ListBox1.ListCount, 0) & " dosya bulundu."
  20. Set klasor = Nothing: Exit Sub
  21. hata: MsgBox "Sürücü boş veya hazır değil!": Label1.Visible = False
  22. End Sub
  23.  
  24. Private Function Liste(yol As String)
  25. Dim dosya As String
  26.  
  27. DoEvents
  28. TextBox1.SetFocus
  29. dosya = Dir(yol & "\" & TextBox1.Text)
  30. ListBox1.RowSource = ""
  31. While dosya <> ""
  32. 'ListBox1.AddItem dosya
  33. ListBox1.AddItem yol & "\" & dosya
  34. Label1.Caption = "Bulunuyor... " & FormatNumber(ListBox1.ListCount, 0) _
  35. & " dosya bulundu."
  36. dosya = Dir
  37. Wend
  38.  
  39. Set fL = Nothing
  40.  
  41. End Function
  42.  
  43. Private Function AltListe(yol As String)
  44. Dim fL As Object, f As Object, dosya As String
  45. DoEvents
  46.  
  47. Set fL = CreateObject("Scripting.FileSystemObject").GetFolder(yol).SubFolders
  48.  
  49. On Error GoTo sonraki
  50. For Each f In fL
  51. TextBox1.SetFocus
  52. dosya = Dir(f.Path & "\" & TextBox1.Text)
  53.  
  54. While dosya <> ""
  55. 'ListBox1.AddItem dosya
  56. ListBox1.AddItem f.Path & "\" & dosya
  57. Label1.Caption = "Bulunuyor... " & FormatNumber(ListBox1.ListCount, 0) _
  58. & " dosya bulundu."
  59. dosya = Dir
  60. Wend
  61.  
  62. AltListe (f.Path)
  63. sonraki:
  64. Next
  65. Set fL = Nothing
  66. End Function
  67.  
  68. Private Sub ListBox1_DblClick(Cancel As Integer)
  69. Dim shell_app As Object
  70.  
  71. Set shell_app = CreateObject("Shell.Application")
  72.  
  73. shell_app.Open "" & ListBox1.Value
  74.  
  75. Set shell_app = Nothing
  76.  
  77. End Sub



******************************************************
VERSİYON 2


[Resim: searchfilesver2.jpg]
Visual Basic
  1. Private arr() As String
  2. Private arr2() As String '********************************
  3. Private Secim As String
  4. Private durdur As Boolean '*******************************
  5.  
  6. Private Sub ComboBox1_Change()
  7. Dim cmb As String
  8. cmb = ComboBox1.Text
  9.  
  10. If combo_hata_control(cmb) Then
  11. MsgBox "Yasak karrdeşiiiim"
  12. SendKeys "{ESC}"
  13. End If
  14.  
  15. End Sub
  16.  
  17. Private Function combo_hata_control( _
  18. cmbo As String) As Boolean
  19. For Each m In arr2
  20. If (m = cmbo) Then _
  21. combo_hata_control = True: Exit For
  22. Next
  23. End Function
  24.  
  25.  
  26. Private Sub dur_Click()
  27. durdur = True
  28. End Sub
  29.  
  30. Private Sub Komut2_Click()
  31. 'Diziyi daha sonraki aşamalarda rahat kullanabilmek
  32. 'yeniden boyutlandırmamız gerekiyor.
  33. Me.dur.Enabled = True
  34. durdur = False
  35. ReDim arr(1 To 1) As String
  36. 'Sütun başlığı..
  37. arr(1) = String$(40, ".") & " DOSYA YOLU " & String$(40, ".")
  38.  
  39. 'İlk etapta Sütun başlığı görünmesi içindir.
  40. ListBox1.RowSourceType = "Liste_Doldur"
  41. DoCmd.MoveSize , , , 6103
  42.  
  43. Me.Tag = 1
  44. With Label1
  45. .Visible = True
  46. .Caption = "Bulunuyor..."
  47. End With
  48. 'Form yüklenirken Combo hareketi 'Secim' değişkenine atanmıştı.
  49. If Secim = "Tüm Bilgisayarda Ara" Then
  50. Call Tum_PC
  51. Else
  52. Call Liste(Replace(Secim, "\", ""))
  53. Call AltListe(Secim)
  54. End If
  55.  
  56. Label1.Caption = "Arama tamamlandı !! Toplam : " & UBound(arr) - 1 & " dosya bulundu"
  57. End Sub
  58.  
  59. Private Sub Tum_PC()
  60. Dim b As Byte
  61.  
  62. ComboBox1.SetFocus
  63. For b = 0 To ComboBox1.ListCount - 2
  64. DoEvents
  65. Call Liste(Replace(ComboBox1.ItemData(b), "\", ""))
  66. Call AltListe(ComboBox1.ItemData(b))
  67. Next
  68.  
  69. End Sub
  70. Private Function Liste(yol As String)
  71. Dim dosya As String
  72.  
  73. DoEvents
  74. TextBox1.SetFocus
  75.  
  76. dosya = Dir(yol & "\" & TextBox1.Text, vbHidden + vbReadOnly + vbSystem)
  77. While dosya <> ""
  78. If durdur Then Exit Function '******************************
  79. Me.Tag = Me.Tag + 1
  80. ReDim Preserve arr(1 To Me.Tag) As String
  81. arr(Me.Tag) = yol & "\" & dosya
  82.  
  83. Label1.Caption = "Bulunuyor... " & FormatNumber(Me.Tag - 1, 0) _
  84. & " dosya bulundu." & vbCrLf & vbCrLf & _
  85. "Bakılan yer : " & vbCrLf & yol & "\"
  86.  
  87. 'Dosya diziye alındıkça liste de güncellenecektir..
  88. ListBox1.RowSourceType = "Liste_Doldur"
  89.  
  90. dosya = Dir
  91. Wend
  92.  
  93. Set fL = Nothing
  94.  
  95. End Function
  96.  
  97. Private Function AltListe(yol As String)
  98. Dim fL As Object, f As Object, dosya As String
  99. DoEvents
  100. Set fL = CreateObject("Scripting.FileSystemObject").GetFolder(yol).SubFolders
  101.  
  102. On Error GoTo sonraki
  103. For Each f In fL
  104. TextBox1.SetFocus
  105. If durdur Then Exit Function '*************************
  106. Label1.Caption = "Bulunuyor... " & FormatNumber(Me.Tag - 1, 0) _
  107. & " dosya bulundu." & vbCrLf & vbCrLf & _
  108. "Bakılan yer : " & vbCrLf & f.Path
  109.  
  110. dosya = Dir(f.Path & "\" & TextBox1.Text, vbHidden + vbReadOnly + vbSystem)
  111.  
  112. While dosya <> ""
  113. If durdur Then Exit Function '****************************
  114. Me.Tag = Me.Tag + 1
  115. ReDim Preserve arr(1 To Me.Tag) As String
  116. arr(Me.Tag) = f.Path & "\" & dosya
  117.  
  118. Label1.Caption = "Bulunuyor... " & FormatNumber(Me.Tag - 1, 0) _
  119. & " dosya bulundu." & vbCrLf & vbCrLf & _
  120. "Bakılan yer : " & vbCrLf & f.Path
  121.  
  122. 'Dosya diziye alındıkça liste de güncellenecektir..
  123. ListBox1.RowSourceType = "Liste_Doldur"
  124.  
  125. dosya = Dir
  126. Wend
  127.  
  128. AltListe (f.Path)
  129. sonraki:
  130. Next
  131. Set fL = Nothing
  132. End Function
  133.  
  134. Private Function Liste_Doldur( _
  135. ctl As Control, varId As Variant, lngRow As Long, lngCol As Long, intCode As Integer)
  136.  
  137. Select Case intCode
  138. Case acLBInitialize
  139. Liste_Doldur = True
  140. Case acLBOpen
  141. Liste_Doldur = Timer
  142. Case acLBGetRowCount
  143. Liste_Doldur = -1
  144. Case acLBGetColumnCount 'Değiştirebilirsiniz..
  145. Liste_Doldur = UBound(arr, 2)
  146. Case acLBGetColumnWidth 'Değiştirebilirsiniz..
  147. Liste_Doldur = 10 * 1440
  148. Case acLBGetValue 'Değiştirebilirsiniz ancak
  149. 'iki boyutlu veya array base 0 durumda farklıdır Ör:
  150. 'Liste_Doldur = arr(lngRow , lngCol )
  151. Liste_Doldur = arr(lngRow + 1)
  152. End Select
  153. End Function
  154.  
  155.  
  156.  
  157. Private Sub ListBox1_DblClick(Cancel As Integer)
  158. Dim shell_app As Object
  159.  
  160. Set shell_app = CreateObject("Shell.Application")
  161.  
  162. shell_app.Open "" & ListBox1.Value
  163.  
  164. Set shell_app = Nothing
  165. End Sub
  166.  
  167. Private Sub Form_Load()
  168. Dim Drives As Object, Drive As Object, z As Byte
  169.  
  170. Erase arr
  171. ComboBox1.RowSource = ""
  172. Set Drives = CreateObject("Scripting.FileSystemObject").Drives
  173.  
  174. With ComboBox1
  175. For Each Drive In Drives
  176. z = z + 1
  177. ReDim arr2(1 To z) As String
  178. If Drive.IsReady Then _
  179. .AddItem Drive & "\": arr2(z) = Drive & "\"
  180. Next
  181.  
  182. .AddItem "Tüm Bilgisayarda Ara" '*******************************
  183. .SetFocus
  184. .Value = "Tüm Bilgisayarda Ara" '************************
  185. Secim = "Tüm Bilgisayarda Ara"
  186. '.Text = ComboBox1.ItemData(ComboBox1.ListCount - 1)
  187. End With
  188.  
  189. Set Drives = Nothing
  190. End Sub
  191.  
  192. Private Sub ComboBox1_Click()
  193. Secim = ComboBox1.Text
  194. End Sub
  195.  
  196. Private Sub Form_Unload(Cancel As Integer)
  197. Erase arr
  198. Erase arr2
  199. Secim = Empty
  200. ' ComboBox1.RowSource = ""
  201. End Sub
  202.  
  203. Private Sub Form_Open(Cancel As Integer)
  204.  
  205. DoCmd.MoveSize , , , 4880
  206.  
  207. End Sub




Eklenti Dosyaları
.rar   Dosya_Ara_Acc_2.rar (Boyut: 43,46 KB / İndirilme: 739)
.rar   Listeye_Diziyle_Alma_VER2.rar (Boyut: 46,14 KB / İndirilme: 683)



  Alıntı
Bu mesajı beğenenler:
#2
Zeki Bey, nasıl desem de anlatabilsem?! Harika!!!

Çok hızlı, çok kullanışlı... Tebrikler....
Javascript
  1. this.setState({sign:"Here comes the sun...."})







  Alıntı
Bu mesajı beğenenler:
#3
Rica ederim, paylaşıma devam...



  Alıntı
Bu mesajı beğenenler:
#4
Teşekkürler. Oldukça güzel bir çalışma



  Alıntı
Bu mesajı beğenenler:
#5
Beğendiğinize sevindim Adnan Bey.



  Alıntı
Bu mesajı beğenenler:
#6
Paylaşımınıza çok teşekkürler.



  Alıntı
Bu mesajı beğenenler:


Benzer Konular...
Konu: Yazar Cevaplar: Gösterim: Son Mesaj
  Dosya kopyalama (Yapay Progressbar) Zeki Gürsoy 9 7.042 23-10-2023, 08:54
Son Mesaj: ates2014
  Vba Kod Içine Depolanmış Lisanslama örneği palmbeach 4 526 03-10-2022, 17:17
Son Mesaj: palmbeach
  Resim, Video, Müzik, Ms Offıce Belge, Dosya Isimlerini Düzenleme(arşivleme) dsezgin 5 1.050 18-11-2021, 14:31
Son Mesaj: onur_can
  Daimi Arama Programı grdlsv 0 1.226 01-12-2019, 11:32
Son Mesaj: grdlsv
  Dosya Arşivlemek Için Kısa Bir Kod örneği hedefkaya 1 1.064 23-11-2019, 03:44
Son Mesaj: dsezgin
  FTP ye çoklu dosya gönderimi (upload) beab05 20 11.931 28-10-2019, 19:26
Son Mesaj: umits
  Meslek Liseleri Için Beceri Eğitimi Dosya Programı sefersanli 2 962 26-09-2019, 22:00
Son Mesaj: halily
  Formda sağ cilik çözümü ve örneği mengene 2 1.138 14-02-2019, 11:02
Son Mesaj: özgülapt

Foruma Git:


Bu konuyu görüntüleyen kullanıcı(lar): 1 Ziyaretçi