|
드라이브 남은 공간을 GetDiskFreeSpace API로 하는방법도 있습니다.
프로그램으로 주기적으로 얼마남았는지 확인해서
남은 공간 FreeSize가 일정Size가 원하시는 작업을 해주시면 되겠네요
아래 코드를 그대로 같다 붙여 써보시면
현재 실행파일이 있는 디렉토리의 전체 Size와 남은 공간이 나옵니다.
그럼
HINSTANCE hInst;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
hInst=HInstance;
}
//---------------------------------------------------------------------------
void GetDvrDir(LPSTR lpDir,int nSize)
{
int len;
GetModuleFileName(hInst,lpDir,nSize);
len=strlen(lpDir);
while( len>0 && lpDir[len]!='\\' )
{
lpDir[len]=0;
len--;
}
if(lpDir[len]=='\\')
lpDir[len]=0;
}
void GetDiskInfo(LONGLONG *pTotal,LONGLONG *pFree)
{
char szDir[MAX_PATH];
DWORD dwSectorsPerCluster;
DWORD dwBytesPerSector;
DWORD dwNumberOfFreeClusters;
DWORD dwTotalNumberOfClusters;
__int64 nBytesPerCluster;
__int64 nFreeBytes;
__int64 nTotalBytes;
//__int64 nTotal,nFree;
//char buf[80],buf2[80];
GetDvrDir(szDir,sizeof(szDir));
GetDiskFreeSpace(szDir,
&dwSectorsPerCluster,
&dwBytesPerSector,
&dwNumberOfFreeClusters,
&dwTotalNumberOfClusters
);
// perform 64 bits arithmetic
nBytesPerCluster = dwSectorsPerCluster * dwBytesPerSector;
nFreeBytes = nBytesPerCluster * (__int64) dwNumberOfFreeClusters;
nTotalBytes = nBytesPerCluster * (__int64) dwTotalNumberOfClusters;
*pFree =nFreeBytes;
*pTotal=nTotalBytes;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
__int64 tsize,fsize;
GetDiskInfo(&tsize,&fsize);
ShowMessage("Total:"+IntToStr(tsize)+" Free:"+IntToStr(fsize));
}
//---------------------------------------------------------------------------
Sexyguy™*^^* 님이 쓰신 글 :
: 지금 하고 있는 프로젝트가 아주 커다란 데이터를 다루어야하는데, 그 데이터를 모두 메모리에 올려둘 수 없기 때문에 주기적으로 하드 디스크에 저장했다가 메모리로 올리는 방법을 이용하고 있습니다.
:
: 문제는 데이터가 점점 커지다보면 드라이브 공간 부족 메시지가 뜨는데, 이 메시지가 뜨기 전에 자동으로 다른 드라이브로 변경하여 저장하고 싶습니다.
:
: 인터넷으로 검색해보아도 드라이브 공간 부족 메시지가 뜰때 대처방법만 나와있네요.
:
: 정확하게 제가 알고 싶은 것은 드라이브의 몇 MB가 남았을 때, 또는 그것이 아니라면 드라이브의 몇 %가 남았을 때 드라이브 공간부족 메시지 뜨는가 입니다. (만약, 레지스트리 정보를 이용한다면 어느 위치인지 알려주시면 감사하겠습니다.)
:
: 날이 많이 덥네요. 더위 조심하시고, 오늘도 즐프하십시오.
: 읽어주셔서 감사합니다.
|