{"id":1218,"date":"2024-07-24T08:00:00","date_gmt":"2024-07-24T00:00:00","guid":{"rendered":"http:\/\/www.wyrcad.com\/?p=1218"},"modified":"2024-07-15T09:58:22","modified_gmt":"2024-07-15T01:58:22","slug":"%e4%bd%bf%e7%94%a8%e9%80%92%e5%bd%92%e6%96%b9%e6%b3%95%ef%bc%8c%e9%81%8d%e5%8e%86%e6%8c%87%e5%ae%9a%e7%9b%ae%e5%bd%95","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=1218","title":{"rendered":"\u4f7f\u7528\u9012\u5f52\u65b9\u6cd5\uff0c\u904d\u5386\u6307\u5b9a\u76ee\u5f55"},"content":{"rendered":"\n<p>Dim FolderArray(), FileArray() As String &#8216;\u5168\u540d<br>Dim FolderCount, FileCount As Integer<\/p>\n\n\n\n<p>Dim I, J As Integer<br>SearchFiles &#8220;E:\\&#8221;, &#8220;*&#8221;, True &#8216;\u67e5\u627e\u6240\u6709\u6587\u4ef6<br>If <a href=\"https:\/\/www.wyrcad.com\/?p=798\">IsEmptyArray<\/a>(FileArray) Then Exit Sub<br>For I = LBound(FolderArray) To UBound(FolderArray)<br>Debug.Print FolderArray(I)<br>Next I<br>Debug.Print FolderCount; &#8220;Folders&#8221;<br>For I = LBound(FileArray) To UBound(FileArray)<br>Debug.Print FileArray(I)<br>Next I<br>Debug.Print FileCount; &#8220;Files&#8221;<br>&#8216;\u8c03\u7528\u793a\u4f8b(\u652f\u6301\u901a\u914d\u7b26)<br>&#8216;SearchFiles &#8220;C:\\Program Files\\WinRAR\\&#8221;, &#8220;&#8221; &#8216;\u67e5\u627e\u6240\u6709\u6587\u4ef6 &#8216;SearchFiles &#8220;C:\\Program Files\\WinRAR\\&#8221;, &#8220;.exe&#8221; &#8216;\u67e5\u627e\u6240\u6709exe\u6587\u4ef6<br>&#8216;SearchFiles &#8220;C:\\Program Files\\WinRAR\\&#8221;, &#8220;in.exe&#8221; &#8216;\u67e5\u627e\u6587\u4ef6\u540d\u4e2d\u5305\u542b\u6709 in \u7684exe\u6587\u4ef6<\/p>\n\n\n\n<p>Private Function SearchFiles(sTargetPath As String, sPartialName As String, Optional bAllPaths As Boolean = True)<br>Dim I, J As Integer<br>Dim SubFolderCount As Long<br>Dim SubFolderArray() As String &#8216;\u5b50\u6587\u4ef6\u5939\u5168\u540d<br>Dim sPath As String &#8216;\u6587\u4ef6\u540d\u6216\u5b50\u6587\u4ef6\u5939\u77ed\u540d<br>If Right(sTargetPath, 1) &lt;> &#8220;\\&#8221; Then sTargetPath = sTargetPath &amp; &#8220;\\&#8221;<br>FolderCount = FolderCount + 1<br>ReDim Preserve FolderArray(1 To FolderCount)<br>FolderArray(FolderCount) = sTargetPath<br>sPath = Dir(<a href=\"https:\/\/www.wyrcad.com\/?p=1239\">GetFullName<\/a>(sTargetPath, sPartialName)) &#8216;\u67e5\u627e\u7b2c\u4e00\u4e2a\u6587\u4ef6<br>Do While Len(sPath) &#8216;\u5faa\u73af\u5230\u6ca1\u6709\u6587\u4ef6\u4e3a\u6b62<br>FileCount = FileCount + 1<br>ReDim Preserve FileArray(1 To FileCount)<br>FileArray(FileCount) = sTargetPath &amp; sPath &#8216;\u5c06\u6587\u4ef6\u76ee\u5f55\u548c\u6587\u4ef6\u540d\u7ec4\u5408,\u5e76\u5b58\u653e\u5230\u6570\u7ec4\u4e2d<br>sPath = Dir &#8216;\u67e5\u627e\u4e0b\u4e00\u4e2a\u6587\u4ef6<br>DoEvents &#8216;\u8ba9\u51fa\u63a7\u5236\u6743<br>Loop<br>If Not bAllPaths Then Exit Function<br>sPath = Dir(sTargetPath, vbDirectory) &#8216;\u67e5\u627e\u7b2c\u4e00\u4e2a\u6587\u4ef6\u5939<br>Do While Len(sPath) &#8216;\u5faa\u73af\u5230\u6ca1\u6709\u6587\u4ef6\u5939\u4e3a\u6b62<br>If Left(sPath, 1) &lt;> &#8220;.&#8221; Then &#8216;\u4e3a\u4e86\u9632\u6b62\u91cd\u590d\u67e5\u627e<br>If GetAttr(GetFullName(sTargetPath, sPath)) And vbDirectory Then &#8216;\u5982\u679c\u662f\u6587\u4ef6\u5939\u5219\u2026 \u2026<br>SubFolderCount = SubFolderCount + 1<br>ReDim Preserve SubFolderArray(1 To SubFolderCount)<br>SubFolderArray(SubFolderCount) = GetFullName(sTargetPath, sPath) &amp; &#8220;\\&#8221; &#8216;\u5c06\u76ee\u5f55\u548c\u6587\u4ef6\u5939\u540d\u79f0\u7ec4\u5408\u5f62\u6210\u65b0\u7684\u76ee\u5f55,\u5e76\u5b58\u653e\u5230\u6570\u7ec4\u4e2d<br>End If<br>End If<br>sPath = Dir &#8216;\u67e5\u627e\u4e0b\u4e00\u4e2a\u6587\u4ef6\u5939<br>DoEvents &#8216;\u8ba9\u51fa\u63a7\u5236\u6743<br>Loop<br>For I = 1 To SubFolderCount &#8216;\u4f7f\u7528\u9012\u5f52\u65b9\u6cd5\uff0c\u904d\u5386\u6240\u6709\u76ee\u5f55<br>SearchFiles SubFolderArray(I), sPartialName<br>Next<br>End Function<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dim FolderArray(), FileArray() As String &#8216;\u5168\u540dDim F &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=1218\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u4f7f\u7528\u9012\u5f52\u65b9\u6cd5\uff0c\u904d\u5386\u6307\u5b9a\u76ee\u5f55\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,21],"class_list":["post-1218","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-kepu"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1218"}],"version-history":[{"count":3,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1218\/revisions"}],"predecessor-version":[{"id":1243,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1218\/revisions\/1243"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}