如何取某个目录下的下面几个参数:1.所有文件名
2.文件的大小
3.最新修改日期

解决方案 »

  1.   

    Option  Explicit  
     
    Dim  m_lngFileCount  As  Long  定义计数器  
     
    Dim  m_objFSO  As  Scripting.FileSystemObject  定义文件系统对象  
     
    Sub  Main()  
     
    Set  m_objFSO  =  New  Scripting.FileSystemObject  
     
    m_lngFileCount  =  0  
     
    CheckFolder  "C:\"  
     
    Debug.Print  "C盘下GIF文件总数:  "  &  m_lngFileCount  
     
    End  Sub  
     
    Sub  CheckFolder(strPath  As  String)  
     
    Dim  objFolder  As  Scripting.Folder  文件夹对象  
     
    Dim  objFile  As  Scripting.File  文件对象  
     
    Dim  objSubdirs  As  Scripting.Folders  文件夹集合对象  
     
    Dim  objLoopFolder  As  Scripting.Folder  文件夹对象  
     
     
    Debug.Print  "Checking  directory  "  &  strPath  
     
    Set  objFolder  =  m_objFSO.GetFolder(strPath)    
     
    检查目录中的文件  
     
    For  Each  objFile  In  objFolder.Files  
     
    If  UCase$(Right$(objFile.ShortPath,  4))  =  ".GIF"  Then    
     
    这一段是条件检查,但找到的文件是否符合给定的条件,这儿通过取文件名的  
     
    最后4位看是不是“.GIF“来判断文件是否是GIF文件。  
     
    m_lngFileCount  =  m_lngFileCount  +  1  
     
    找到指定条件的文件后进行相应的操作,这儿是把计数器加一。  
     
    End  If  
     
    Next  objFile    
     
    在所有子目录中循环,计数。  
     
    Set  objSubdirs  =  objFolder.SubFolders  
     
    For  Each  objLoopFolder  In  objSubdirs  
     
    CheckFolder  objLoopFolder.Path    
     
    递归调用CheckFolder子过程,实现目录树的遍历。  
     
    Next  objLoopFolder    
     
    Set  objSubdirs  =  Nothing  
     
    Set  objFolder  =  Nothing  
     
     
    End  Sub