Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 24-08-2010
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Poder: 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
  #2  
Antiguo 31-08-2010
kenychy kenychy is offline
Miembro
 
Registrado: ago 2010
Posts: 45
Poder: 0
kenychy Va por buen camino
Tio, yo opte por una permuta para delphi, necesito si esta entre tus posibilidades que me traduscas este codigo para delphi
Responder Con Cita
  #3  
Antiguo 31-08-2010
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Poder: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Código Delphi [-]
function SetFileSize(FileName: String; Size: int64): boolean;
var
  Hi: DWORD;
  Attributes: DWORD;
  hFile: THandle;
  R: integer;
begin
  Hi:= DWORD(Size shr 32);
  Result:= false;
  Attributes:= GetFileAttributes(PCHAR(FileName));
  if(Attributes = DWORD(-1)) then Attributes:= FILE_ATTRIBUTE_NORMAL;
  SetFileAttributes(PCHAR(FileName), FILE_ATTRIBUTE_NORMAL);
  hFile:= CreateFile(PCHAR(FileName), GENERIC_WRITE, 0, nil, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0);
  if hFile <> THandle(-1) then
  begin
    if SetFilePointer(hFile, DWORD(Size), @Hi, FILE_BEGIN) <> DWORD(-1) then
    begin
      Result:= SetEndOfFile(hFile);
    end;
    CloseHandle(hFile);
  end;
  SetFileAttributes(PCHAR(FileName), Attributes);
end;


Saludos.
Responder Con Cita
  #4  
Antiguo 19-11-2010
kenychy kenychy is offline
Miembro
 
Registrado: ago 2010
Posts: 45
Poder: 0
kenychy Va por buen camino
gracias hermano. su ayuda es impresindible.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
como saber el tamaño de un fichero kenychy C++ Builder 13 19-11-2010 16:46:59
¿Cómo puedo saber el tamaño que debo asignar al buffer? MON___ API de Windows 5 02-02-2008 22:08:02
Como controlar el tamaño de un fichero subido al servidor lazar PHP 7 06-03-2007 01:27:22
Como asignar el tamaño de papel en QuickRep?? AndGaG Impresión 2 02-07-2006 21:51:12
Obtener Todo El Registro De Una Tabla Aunque Aunque Este Agrupado Por 2 Campos agova SQL 6 11-08-2004 15:48:14


La franja horaria es GMT +2. Ahora son las 02:24:25.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi