Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   Obtener tamaño de archivo con error (https://www.clubdelphi.com/foros/showthread.php?t=83185)

jars 20-05-2013 19:40:58

Obtener tamaño de archivo con error
 
Hola amigos, estoy usando hace ya algun tiempo la siguiente funcion para obtener el tamaño de un archivo pero en un cliente que tiene instalado Windows server 2008 standard de 32 bits esta funcion debuelve una fecha:
Código Delphi [-]
function GetHugeFileSize(const Filename: TFileName): Int64;
var
  SearchRec: TSearchRec;
begin
  if FindFirst(Filename, faAnyFile, SearchRec) = 0 then
  begin
    Result := (Int64(SearchRec.FindData.nFileSizeHigh) shl 32)
               or SearchRec.FindData.nFileSizeLow;
    FindClose(SearchRec);
  end else
    Result := -1;
end;
Alguien tiene idea de que puede estar pasando?
Si existe otra forma de tomar el tamaño exacto de un archivo en una unidad de red comentenla.
Gracias.

ecfisa 20-05-2013 21:04:24

Hola jars.

Proba si te funciona de este modo:
Código Delphi [-]
function GetFileSizeEx(hFile: THandle; var lpFileSize: Int64): BOOL; stdcall; external 'kernel32.dll';

function GetHugeFileSize(aFileName: TFileName): Int64;
var
  hnd : THandle;
begin
  hnd := CreateFile(PChar(aFileName),
                    GENERIC_READ,
                    0,
                    nil,
                    OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,
                    0);
  if not GetFileSizeEx(hnd, Result) then
    RaiseLastOSError;
end;

// Ejemplo de llamada:
...
begin
  ShowMessage(IntToStr(GetHugeFileSize('C:\...\Nombre_Archivo.Ext')));
end;
Minimum supported server Windows Server 2003 [desktop apps only] (GetFileSizeEx)

Saludos :)

jars 20-05-2013 21:15:19

Gracias ecfisa, ahora que lo mencionas, si en esa maquina lo ejecuto como aplicación funciona bien pero como servicio, que es como debe correr, me da el error.


La franja horaria es GMT +2. Ahora son las 11:40:43.

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