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

  • 相关阅读:
    201671010456-张琼 实验三作业互评与改进
    阅读《构建之法》后的相关问题
    个人作业-软件工程实践总结
    团队作业第二次—项目选题报告
    结对第二次—文献摘要热词统计及进阶需求
    结对第一次—原型设计(文献摘要热词统计)
    第一次作业-准备篇
    个人作业——软件工程实践总结作业
    团队作业第二次—项目选题报告
    结对第二次—文献摘要热词统计及进阶需求
  • 原文地址:https://www.cnblogs.com/yongfeiuall/p/4134204.html
Copyright © 2011-2022 走看看