zoukankan      html  css  js  c++  java
  • [唐胡璐]VBS技巧 Find a File Recursively(递归查找文件)

       '-----------------------------------------------------------------------
      'Function: FindFileRecursively
      'Finds the first instance of a file within the root folder or one of its subfolders
      '
      'Remarks:
      '   Uses recursion
      '
      'Arguments
      '   ByVal strRootFolder - As String (absolute folder)
      '   ByVal strFilename - As String
      '
      'Returns:
      '   String with full file pathname based on root folder and file name
      '
      'Owner:
      '
      'Date:
      '
      '-----------------------------------------------------------------------    
       PublicFunction FindFileRecursively(ByVal strRootFolder, ByVal strFilename)
          Dim FSO    
          Dim strFullPathToSearch    
          Dim objSubFolders, subfolder    
       
          Set FSO = CreateObject("Scripting.FileSystemObject")    
          'Initialize function    
          FindFileRecursively = ""    
          'Check that filename is not empty    
          If strFileName = ""ThenExitFunction    
          'Get full file pathname    
          strFullPathToSearch = strRootFolder & "\" & strFilename    
          'Check if root folder exists    
          If FSO.FolderExists(strRootFolder) Then        
              'Check if file exists under root folder        
              If FSO.FileExists(strFullPathToSearch) Then            
                  FindFileRecursively = strFullPathToSearch        
              Else            
                  'Get subfolders            
                  Set objSubFolders = FSO.GetFolder(strRootFolder).SubFolders            
                  ForEach subfolderin objSubFolders                
                      strFullPathToSearch = strRootFolder & "\" & subfolder.name                
                      FindFileRecursively = FindFileRecursively(strFullPathToSearch, strFilename)                
                      If FindFileRecursively <> ""Then                    
                          ExitFor                
                      EndIf            
                  Next        
              EndIf    
          EndIf
      EndFunction

  • 相关阅读:
    mvc使用model进行数据的增加修改的方法
    c#导出word在iis部署上报异常
    做个转圈圈的咚咚
    VS2008中AJAX的部署问题(工具箱中无AJAX Extensions选项卡)
    关于 AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. 错误
    ASP.NET关于继承DropDownList的自定义DDL控件
    线性表顺序表示的C#实现(参考数据结构(C语言版))
    WORD2003出现的乱码
    线性表链式表示的C#实现(参考数据结构(C语言版))
    有错误先找自己的原因(若你百度不出为什么vista开网页慢,可以来试试这方法)
  • 原文地址:https://www.cnblogs.com/yongfeiuall/p/4134204.html
Copyright © 2011-2022 走看看