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

[µo°Ý] ¦h¼h¸ê®Æ§¨´M§äÀɮתº°ÝÃD

¦^´_ 10# GBKEE


    ¶Wª©¤j¤j,¹ê¦b¤Ó¯«¤F

¦h¾Ç¤F¤@­ÓInStrªº¥Îªk,¯u¦n¥Î­C

¦Ü©óSet Fs = CreateObject("Scripting.FileSystemObject").GetDRIVE("C:")
    Set Fs = Fs.ROOTFOLDER.SubFolders '®Ú¥Ø¿ý\¸ê®Æ§¨ª«¥ó¶°¦X
¤]¬O¤p§Ì²Ä¤@¦¸¬Ý¨ì
¦n¤è«K!

·P¿E¦Ü·¥!!
PKKO

TOP

¥»©«³Ì«á¥Ñ no3-taco ©ó 2015-6-16 04:36 ½s¿è

ª±ª±¬Ý¡A²¤Æ¹Lªº»¼°jª©
  1. Sub ³o¸Ì°õ¦æ()
  2. Dim rw As Long, ilevel As Long: rw = 1: ilevel = 0
  3. GetSubs "C:\Users\Administrator\Desktop" & "\", rw, ilevel '©I¥s°Æµ{¦¡"#­×§ï¸ô®|#
  4. End Sub
  5. Sub GetSubs(sPath As String, rw As Long, ilevel As Long)
  6. Dim ary1() As String: ReDim ary1(0): Dim sName
  7. sName = Dir(sPath, vbDirectory)
  8. Do While sName <> ""
  9.     On Error Resume Next  '¦³¿ù»~¸õ¹L
  10.     If sName <> "." And sName <> ".." And (GetAttr(sPath & sName) And vbDirectory) = vbDirectory Then
  11.     'If Err = 0 Then  '¨S¦³¿ù»~®É
  12.         ReDim Preserve ary1(UBound(ary1) + 1)
  13.         ary1(UBound(ary1)) = sName
  14.     End If ': End If
  15.     sName = Dir
  16. Loop
  17. For i = 1 To UBound(ary1)
  18.     rw = rw + 1
  19.     GetSubs sPath & ary1(i) & "\", rw, ilevel + 1    '»¼°j©I¥s
  20. Next i
  21. sName = Dir(sPath)
  22. If Dir(sPath & [A1]) = [A1] Then
  23.    Workbooks.Open sPath & [A1]    '¶}±ÒÀÉ®×
  24. End
  25. End If
  26. End Sub
½Æ»s¥N½X

TOP

¦^´_ 8# Hsieh
¤j¤j³Ìªñ¨Ï¥Î³o­Óµ{¦¡½X®É¡Aµo²{±`±`·j­Ó2~3¼h´N¤£·j¤F(¨S¦b·j¤U¥h¡A­ì©l¸ê®Æ§¨¦@¦³24­Ó 2014/1..../12 &2015/1..../12)¡A
«Ü©Ç><¡A¤£¹L¦³ªº®É­Ô®É¦¨¥\ªº

TOP

¥»©«³Ì«á¥Ñ ­ã´£³¡ªL ©ó 2015-9-9 17:27 ½s¿è

¦^´_ 13# ui123


2003¥H¤W¨S¤F FileSearch¡A¹ï³o¦h¼h·jÀɹê¦bÀYµh¡A¤£¬O±M¦æ¼gªº¡A°Ñ¦Ò¬Ý¬Ý¡I
¢Ï¢°½Ð¥ý¿é¤J¡eÀɮצWºÙ.°ÆÀɦW¡f¡A¶È·j¯Á°õ¦æÀɮצP¤@¼h¤Î¥H¤U¤l¸ê®Æ§¨ªºÀɮסA
­Y»P¹ê»Ú»Ý¨D¦³¤£¨¬ÂI¡A½Ð¦Û¦æ­×§ï¡G
  1. Sub Get_File()
  2. Dim OBJ, xD, xFile$, Urr, U, G, GF, K, xB As Workbook
  3. Set OBJ = CreateObject("Scripting.FileSystemObject")
  4. Set xD = CreateObject("Scripting.Dictionary")
  5. Urr = Array(ThisWorkbook.Path)
  6. ¡@
  7. RE_GET:
  8. For Each U In Urr
  9. ¡@¡@xFile = U & "\" & [A1].Value ¡@'Àɮק¨¸ô®|+¢Ï¢°ÀɦW.°ÆÀɦW
  10. ¡@¡@If Dir(xFile) <> "" Then Set xB = Workbooks.Open(xFile): Exit Sub¡@ '§ä¨ìÀɮסA¶}±Ò¨Ã¸õ¥X
  11. ¡@
  12. ¡@¡@Set GF = OBJ.GetFolder(U).SubFolders  ¡@'¨ú±o¥»¼h¤l¸ê§¨
  13. ¡@¡@If GF.Count > 0 Then ¡@   
  14. ¡@¡@¡@¡@For Each G In GF: K = K + 1: xD(K) = G.Path: Next¡@ '±N¤l¸ê®Æ§¨¯Ç¤J¦r¨åÀÉ
  15. ¡@¡@End If
  16. Next
  17. ¡@
  18. If K > 0 Then Urr = xD.items: xD.RemoveAll: K = 0: GoTo RE_GET '­Y¦r¨åÀɦ³¤º®e¡A¦A¥h§äÀÉ®×
  19. MsgBox "§ä¤£¨ì¥Ø¼ÐÀɮסI¡@"
  20. End Sub
½Æ»s¥N½X
¡@

TOP

¦^´_ 7# ui123
  1. '¨Ï¥ÎFSO·j¯Á¤å¥ó©Î¬O¤å¥ó夹
  2. Public Function FSOFileSearch(Optional ByVal SearchPath As String, _
  3.          Optional ByVal objFolder As Object = Nothing, _
  4.          Optional ByVal SearchName As String = vbNullString, _
  5.          Optional ByVal SearchSub As Boolean = True, _
  6.          Optional ByVal SearchType As Long = 1) As Collection
  7.         Dim FSO       As Object
  8.         Dim Filter()  As String
  9.         Dim subSearch As Collection
  10.         Dim I As Long, J As Long
  11.         Dim objSub    As Object
  12.         
  13. 1       Set FSOFileSearch = New Collection
  14. 2       If objFolder Is Nothing Then
  15. 3         If Len(SearchPath) = 0 Then Exit Function
  16. 4         Set FSO = CreateObject("Scripting.FileSystemObject")
  17. 5         Set objFolder = FSO.GetFolder(SearchPath)
  18. 6         Set FSO = Nothing
  19. 7         If objFolder Is Nothing Then Exit Function
  20. 8       End If
  21.         
  22. 9       If Len(SearchName) < 1 Then SearchName = "*.*|*"
  23. 10      Filter = Split(Replace(SearchName, "|", vbNullChar), vbNullChar)
  24. 11      If Len(SearchPath) Then
  25. 12        For I = 0 To UBound(Filter)
  26. 13          Filter(I) = LCase$(Trim$(Filter(I)))
  27. 14          If Len(Filter(I)) = 0 Then
  28. 15            If I = UBound(Filter) Then Exit For
  29. 16            For J = I + 1 To UBound(Filter)
  30. 17              If Len(Filter(J)) Then
  31. 18                Filter(I) = Filter(J)
  32. 19                Filter(J) = vbNullString
  33. 20                I = J - 1
  34. 21                Exit For
  35. 22              End If
  36. 23            Next J
  37. 24            If J > UBound(Filter) Then Exit For
  38. 25          End If
  39. 26        Next I
  40. 27        ReDim Preserve Filter(I - 1)
  41. 28        SearchName = Join(Filter, vbNullChar)
  42. 29      End If
  43.         
  44. 30      If SearchType And 1& Then
  45. 31        For Each objSub In objFolder.Files
  46. 32          With objSub
  47. 33            For I = 0 To UBound(Filter)
  48. 34              If LCase(.Name) Like Filter(I) Then
  49. 35                FSOFileSearch.Add .Path
  50. 36                Exit For
  51. 37              End If
  52. 38            Next I
  53. 39          End With
  54. 40        Next objSub
  55. 41      End If
  56.         
  57. 42      If SearchType And 2& Then
  58. 43        For Each objSub In objFolder.SubFolders
  59. 44          With objSub
  60. 45            For I = 0 To UBound(Filter)
  61. 46              If LCase(.Name) Like Filter(I) Then
  62. 47                FSOFileSearch.Add .Path
  63. 48                Exit For
  64. 49              End If
  65. 50            Next I
  66. 51          End With
  67. 52        Next objSub
  68. 53      End If
  69.         
  70. 54      If SearchSub Then
  71. 55        For Each objSub In objFolder.SubFolders
  72. 56          DoEvents
  73. 57          Set subSearch = FSOFileSearch(, objSub, SearchName, SearchSub, SearchType)
  74. 58          With subSearch
  75. 59            For J = 1 To .Count
  76. 60              FSOFileSearch.Add .Item(J)
  77. 61            Next J
  78. 62          End With
  79. 63          Set subSearch = Nothing
  80. 64        Next objSub
  81. 65      End If
  82. End Function

  83. Sub TestSearch()
  84.   Dim I       As Long
  85.   Dim Search  As Collection

  86.   Set Search = FSOFileSearch(ThisWorkbook.Path, , [A1], True, 1)
  87.   For I = 1 To Search.Count
  88.     Workbooks.Open Search(I)
  89.   Next I
  90. End Sub
½Æ»s¥N½X
­nª`·Nªº¬O¦pªGA1单¤¸®æ¤¤ªº内®e¥]§t¤Ç°t¦r²Å¡A将会³Q¦p´Á¨Ï¥Î¡A¤ñ¦pA1¤¤输¤J*.*|*将会·j¯Á¥X«ü©w¸ô径¤¤ªº©Ò¦³¤å¥ó¡A*.XLS[XM]则ªí¥Ü·j¯Á¦Z缀为.XLSX¤Î.XLSM¤å¥ó¡]ÉO*.XLSX|*.XLSM¬Û¦P¡A|ªí¥ÜOr)¡CA1¤¤ªº内®e¥u¯à¥]§t¤å¥ó¦W¡A¦Ó³Ì¦n¤£­n¥]§t¥Ø录¦W¡C

TOP

¨ä¹ê´X¤Ñ«e¤w·Q½Ð°Ý, ¬d¸ßºû¤@Àɮתº³Ì²³æ¦Ó§Ö¤èªk¥i¯à¬O dos ªº dir/s , ¦ý¥Ø«e°NÀ´±o¥ý¾É¤J txt ÀÉ®×, ¦p ¥ý³]©w findx ="cme.exe /c dir/s c:\file.txt > speciafyDrive:\reslt.txt", µM«á¤Þ¥Î shell(finx), ¦A open result.txt , ¥Îinstr §ä"\" ½T»{Àɮ׬O§_¦s¦b, ¦ý³o¼Ë­n¥ý°µ¤@¦¸¼g¤J, ¦Ó§Ú·Q°Ýªº¬O¥i§_¥Hª½±µ±N¬d¸ß¸ê®Æ¼g¤J¼u¦C¤¤, ¨Dª¾¡C

TOP

°Ñ¦Ò¬Ý¬Ý!²³æªºFSO·j´M
  1. Sub ©I¥s³B() '©I¥s³B
  2. Dim FirstPath: FirstPath = "C:\Users\Administrator\Desktop\" '¸ô®|....¦Û¦æ­×§ï
  3.     SearchFile FirstPath
  4. End Sub

  5. Sub SearchFile(ByVal xPath As String)
  6. Dim objPath As Object, xFile As Object, xFolder As Object
  7. Set objPath = CreateObject("Scripting.FileSystemObject").getfolder(xPath)
  8. For Each xFile In objPath.Files         '¸Ó¼hÀɮצWºÙ¶°¦X
  9.     If xFile.Name = [a1] Then           '¶}±ÒªºÀɮצWºÙ....¦Û¦æ­×§ï
  10.         Workbooks.Open xFile.Path       '¶}±ÒÀÉ®×
  11.         End
  12.     End If
  13. Next
  14. For Each xFolder In objPath.SubFolders '¬Y¼h¤l¸ê®Æ§¨¶°¦X
  15.     SearchFile xFolder.Path
  16. Next
  17. End Sub
½Æ»s¥N½X

TOP

¦^´_ 16# ikboy

¨º­ÓCMDªº¤]¤£¤ÓÀ´, ¸ÕµÛ¼g, °Ñ¦Ò¬Ý¬Ý¡G
http://forum.twbts.com/thread-15063-1-1.html

TOP

¦^´_ 8# Hsieh
¤µ¤Ñ¸Õ¡A¦U¼h³£»`ªº¨ì¤F
§Ú¦b¬ã¨s¤@¤U....ÁÙ¨Sµo²{¨ä¥L°ÝÃD¡A¦³°ÝÃD¦A°Ý±z¡AÁÂÁÂ~

TOP

        ÀR«ä¦Û¦b : ¡i°µ¤Hªº¶}©l¡j¨C¤@¤Ñ³£¬O¬G¤Hªº¶}©l¡A¨C¤@­Ó®É¨è³£¬O¦Û¤vªºÄµ±§¡C
ªð¦^¦Cªí ¤W¤@¥DÃD