VB怎么获取某个目录(含子目录)所占空间的大小? 
不想挨个加文件的大小啊

解决方案 »

  1.   

    用Api计算。  
       
      在外面dim   一个Double   Totalsize  
      dim   TotalSize   as   Double  
       
      Private   Sub   GetFolderSize(ByVal   PathName   As   String)  
      On   Error   Resume   Next  
       
      Dim   SearchName   As   String  
      Dim   Find_Data   As   WIN32_FIND_DATA  
      Dim   lhandle   As   Long,   ret   As   Long  
       
      Dim   Filehandle   As   Long  
      Dim   i   As   Long  
       
      SearchName   =   PathName   &   "\*.*"  
      lhandle   =   FindFirstFile(SearchName,   Find_Data)  
      ret   =   lhandle  
       
      Do   While   ((ret   <>   0)   And   Running)  
              ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
              'handle   the   file   here  
              ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
              If   (Find_Data.lFileAttributes   And   FILE_ATTRIBUTE_DIRECTORY)   <>   0   Then  
               
                      If   (Left(Find_Data.cFileName,   1)   <>   ".")   Then                 'is   a   directory  
                      'Debug.Print   Pathname   &   "\"   &   TrimZeroSuffix(Find_Data.cFileName)   &   "\"  
                      Call   Addfiles(PathName   &   "\"   &   TrimZeroSuffix(Find_Data.cFileName),   ID)  
                      End   If  
         
              Else  
              'is   a   file  
              'handle   the   file   here  
                TotalSize   =TotalSize   +   ConvertSize(Find_Data.nFileSizeHigh,   Find_Data.nFileSizeLow)  
       
                      'Debug.Print   Pathname   &   "\"   &   TrimZeroSuffix(Find_Data.cFileName)  
              End   If  
              DoEvents  
              ret   =   FindNextFile(lhandle,   Find_Data)  
              CountX   =   CountX   +   1  
       
      Loop  
       
      FindClose   (lhandle)  
      End   Sub
      

  2.   

    引用Microsoft   Scripting   RunTimePrivate fsoTest As New FileSystemObject  
    Private folder1 As Folder  
    -----------------------
    Set folder1 = fsoTest.GetFolder("d:\")  
    debug.print folder1.Size/1024/1024