Ver Mensaje Individual
  #1  
Antiguo 30-06-2006
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Reputación: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Conocer el espacio que ocupa un directorio

Si necesitamos calcular el tamaño que nos ocupa un directorio, podemos hacer lo siguiente:

Código:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TSearchRec sr;
  double tamanyo=0;
  int iAttributes = 0;

  if (FindFirst("c:\\windows\\*.*", iAttributes, sr) == 0)
  {
    tamanyo += sr.Size;
    while (FindNext(sr) == 0)
      tamanyo += sr.Size;
  }
  FindClose(sr);
  ShowMessage(tamanyo);
}
Si este directorio contiene otros subdirectorios, y también queremos conocer el espacio que nos ocupan en disco...

Código:
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
double size=0;

//---------------------------------------------------------------------------
double tamanyo(AnsiString Path)
{
TSearchRec R;
int F = FindFirst(Path + "\\*", faAnyFile, R);
while(F==0)
{
if(R.Name != "." && R.Name != "..")
{
if(R.Attr == faDirectory)
tamanyo(Path + "\\" + R.Name);
else
size+= R.Size;
}
F = FindNext(R);
}
FindClose(R);
return size;
}

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
Label1->Caption = AnsiString(tamanyo("c:\\mirc"));
}
//---------------------------------------------------------------------------
Responder Con Cita