问:用vc如何实现测整个某个文件夹内所有文件的大小总和

解决方案 »

  1.   

    // _findfirst.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"
    #include <io.h>
    #include <iostream>using namespace std;int main(int argc, char* argv[])
    {
        struct _finddata_t fileData;
    unsigned long TotalSize=0;
        long fileHandle = _findfirst("*.*", &fileData);    if(fileHandle == -1L)
            cout << "No files found." << endl;
        else
        {
            cout << "FILE: " << fileData.name;
            cout << " -- " << fileData.size << " bytes" << endl;        int result = _findnext(fileHandle, &fileData);
            while(result == 0 )
            {
                cout << "FILE: " << fileData.name;
                Totalsize+= fileData.size;
                cout << endl;
                result = _findnext(fileHandle, &fileData);
            }        _findclose(fileHandle);
        }
    cout<<"Total Size: "<<TotalSize;
        return 0;
    }
      

  2.   

    // _findfirst.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"
    #include <io.h>
    #include <iostream>using namespace std;int main(int argc, char* argv[])
    {
        struct _finddata_t fileData;
    unsigned long TotalSize=0; //总长度变量
        long fileHandle = _findfirst("c:\\*.*", &fileData);    if(fileHandle == -1L)
            cout << "No files found." << endl;
        else
        {
            cout << "FILE: " << fileData.name;
            cout << " -- " << fileData.size << " bytes" << endl;        int result = _findnext(fileHandle, &fileData);
            while(result == 0 )
            {
                cout << "FILE: " << fileData.name;
                Totalsize+= fileData.size;
                cout << endl;
                result = _findnext(fileHandle, &fileData);
            }        _findclose(fileHandle);
        }
    cout<<"Total Size: "<<TotalSize; //总长度
        return 0;
    }
      

  3.   

    楼上的方法还不错,但是如果能改成WINDOWS下的可能为更好用!
      

  4.   

    怎样调用MFC内的类与方法来实现这个功能呢?而且所要统计的文件夹内都是语音文件,且数据量巨大。
      

  5.   

    BOOL  b;  
    b = FindFile();
    while(b)
    {
         b = FindNextFile();
         if(!filer.IsDirectory() && !filer.IsDots())
         {
             GetFileLength(filer.GetFileName);
         }
     }
      

  6.   

    long lAllFileLen=0;//文件长度
    CString strFileTitle; 
    CFileFind finder; 
    BOOL bWorking = finder.FindFile(“C:\\*.*”); 
    while(bWorking) 

    bWorking=finder.FindNextFile(); 
    strFileTitle=finder.GetFileTitle(); 
    CFile myFile(strFileTitle,CFile::read);
    lAllFileLen=lAllFileLen+myFile.GetLength();
      

  7.   

    哦,忘记了myFile.Close()lAllFileLen=lAllFileLen+myFile.GetLength();
    //--------加在这里
    myFile.Close();
    //----------