Ver Mensaje Individual
  #7  
Antiguo 24-08-2010
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Reputación: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Con la API de Windows permite realizar la misma operación que chsize reservando tamaño incluso mayor que 4.294.967.295 bytes. En este caso no disponemos de una función directa, así que propongo una como esta:

Código:
BOOL SetFileSize(char* FileName, __int64 Size)
{
  bool Result = false;
  LONG Hi = LONG(Size >> 32);
  DWORD Attributes = GetFileAttributes(FileName);
  if(Attributes == -1) Attributes = FILE_ATTRIBUTE_NORMAL;
  SetFileAttributes(FileName, FILE_ATTRIBUTE_NORMAL);
  HANDLE hFile = CreateFile(FileName, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0);
  if(hFile != HANDLE(-1)){
    if(SetFilePointer(hFile, (LONG)Size, &Hi, FILE_BEGIN) != INVALID_SET_FILE_POINTER){
      Result = SetEndOfFile(hFile);
    }
    CloseHandle(hFile);
  }
  SetFileAttributes(FileName, Attributes);
  return Result;
}
Esta función trunca o amplia el fichero si existe o lo crea, en caso contrario.

Saludos.
Responder Con Cita