ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] Application.FileSearch µLªk¨Ï¥Î

¦^´_ 3# h60327
¼g¤F¤@­Óª«¥óÃþ§O¼Ò²Õ¡A¥u¹ê²{§A¦³¥Î¨ìªº³¡¤ÀFileSearch¥\¯à
¨Ï¥Î¤èªk:
1. Project ¤¤´¡¤J¤@­Óª«¥óÃþ§O¼Ò²Õ¡Aª«¥óÃþ§O¼Ò²ÕName§ï¬°clsFileSearch¡A¶K¤W¥H¤Uµ{¦¡½X
  1. Private msLookIn As String
  2. Private msFileName As String
  3. Private mbSearchSubFolders As Boolean
  4. Private mcolFoundFiles As Collection

  5. Private Sub Class_Initialize()
  6.   Set mcolFoundFiles = New Collection
  7. End Sub

  8. Public Property Get LookIn() As String
  9.   LookIn = msLookIn
  10. End Property
  11. Public Property Let LookIn(ByVal sLookIn As String)
  12.   msLookIn = sLookIn
  13. End Property

  14. Public Property Get FileName() As String
  15.   FileName = msFileName
  16. End Property
  17. Public Property Let FileName(ByVal sFileName As String)
  18.   msFileName = sFileName
  19. End Property

  20. Public Property Get SearchSubFolders() As Boolean
  21.   SearchSubFolders = mbSearchSubFolders
  22. End Property
  23. Public Property Let SearchSubFolders(ByVal bSearchSubFolders As Boolean)
  24.   mbSearchSubFolders = bSearchSubFolders
  25. End Property

  26. Public Property Get FoundFiles() As Collection
  27.   Set FoundFiles = mcolFoundFiles
  28. End Property

  29. Public Function Execute() As Long
  30.   Dim oFSO As Object, oFolder As Object
  31.   Dim oFile
  32.   
  33.   Set oFSO = CreateObject("Scripting.FileSystemObject")
  34.   Set mcolFoundFiles = New Collection '²MªÅ
  35.   
  36.   If oFSO.FolderExists(msLookIn) Then
  37.     Set oFolder = oFSO.GetFolder(msLookIn)
  38.     For Each oFile In oFolder.Files
  39.       If oFile.Name Like msFileName Then mcolFoundFiles.Add oFile.Path
  40.     Next
  41.    
  42.     If mbSearchSubFolders Then FindSubFolder oFolder.subfolders
  43.   End If
  44.   
  45.   Execute = mcolFoundFiles.Count
  46. End Function

  47. Private Sub FindSubFolder(ByRef oSub As Object)
  48.   Dim x, oFile
  49.   For Each x In oSub
  50.     For Each oFile In x.Files
  51.       If oFile.Name Like msFileName Then mcolFoundFiles.Add oFile.Path
  52.     Next
  53.    
  54.     FindSubFolder x.subfolders
  55.   Next  
  56. End Sub
½Æ»s¥N½X
2. µM«á§â§AªºCommandButton1_Click()¤¤ªº
    Set fs1 = Application.FileSearch
    §ï¦¨
    Set fs1 = New clsFileSearch
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

        ÀR«ä¦Û¦b : ¯àµ½¥Î®É¶¡ªº¤H¡A¥²¯à´x´¤¦Û¤v§V¤Oªº¤è¦V¡C
ªð¦^¦Cªí ¤W¤@¥DÃD