BOOL fResult;unsigned _int64 i64FreeBytesToCaller;unsigned _int64 i64TotalBytes;unsigned _int64 i64FreeBytes;unsigned int freespace;vectormyFileVector;
fResult = GetDiskFreeSpaceEx ( "D://", (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); if(fResult){ freespace = i64FreeBytesToCaller/1024/1024/1024; if (freespace < 30) { vectormyFileVector; TCHAR path[200]; SetCurrentDirectory("D:\\"); GetCurrentDirectory(200,path); CFileFind finder; BOOL bWorking = finder.FindFile("*.*"); while (bWorking) { bWorking = finder.FindNextFile(); CString filename= finder.GetFileName(); if(filename == "." || filename == ".."||\ filename == "RECYCLER" || filename == "System Volume Information") { //……………… } else if(finder.IsDirectory()) { char chtemp[16]; sprintf(chtemp,"%s",filename); myFileVector.push_back(chtemp); } }//End while bWorking if(myFileVector.size() > 0) { sort(myFileVector); } //int a= myFileVector.size(); CString strdeletefile; while(freespace < 30) { if(myFileVector.size() > 0) { strdeletefile.Format("%s",myFileVector.at(0)); myFileVector.erase(&myFileVector[0]); DeleteDirectory(strdeletefile);// 调用删除文件(strdeletfile是文件夹名) fResult = GetDiskFreeSpaceEx ( "D://", (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); } else{ break; } if(fResult) { freespace = i64FreeBytesToCaller/1024/1024/1024; } else { break; } }//End while freespace }//End if freespace}//End if fResult
//得到磁盘剩余空间大小,得到文件夹名,文件夹名为日期格式,如20120701125900《2012年7月1日12时59分00秒》