Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Funcion FindFirst Ayuda en Atributo Fecha (https://www.clubdelphi.com/foros/showthread.php?t=85104)

chopin_fev 29-01-2014 14:10:05

Funcion FindFirst Ayuda en Atributo Fecha
 
Junto con saludar a los amigos del Foro, la ayuda que necesito es de la función *FindFirst*: Esta devuelve al ejecutarla: Nombre de Archivo/Tamaño/Fecha. Necesito resolver el dato de Fecha, ya que devuelve en formato entero (ej: PRUEBA.TXT/150243/1143452647), y lo que se necesita es: (PRUEBA.TXT/150243/28-01-2014 10:30). Esta conversión quizás tiene alguna fórmula que no he encontrado en el google y en el Foro, si alguen se ha topado con esto.

Gracias. Saludos.


El ejemplo de esta Función:

function TfrmActUMC.ListaArchivos(dirPadre:string): TStringList ;
var sr: TSearchRec;
sXX: string ;
nXX: Integer ;
lB : Boolean ;
begin
sXX := '';
nXX := 1 ;
lB := False;
Result := TStringList.Create;
if FindFirst(dirPadre + '*', faAnyFile, sr) = 0 then
repeat
sXX:= LeftStr(Trim(sr.Name),1) ;
lB := ( sXX[nXX] in ['1'..'9'] );
if (sr.Attr and faDirectory = 0) or (sr.Name <> '.')
and (sr.Name <> '..') and ( lB ) then
begin
Result.Add(sr.Name+' /'+IntToStr(sr.Time) );
dxMDfWMTS.Append;
dxMDfWMTSsarchivo.AsString:= Trim(sr.Name) ;
dxMDfWMTSnsize.AsInteger := sr.Size ;
dxMDfWMTSstfecha.AsString := Trim(IntToStr(sr.Time)) ;
dxMDfWMTS.Post ;
end ;
until FindNext(sr) <> 0;
FindClose(sr);
end ;

ecfisa 29-01-2014 15:32:45

Hola chopin_fev.

Por favor, cuando incluyas código Delphi en tus mensajes usa TAG's



En primer término te aconsejo usar un procedimiento en lugar de la función para evitar las fugas de memoria ya que nunca liberas la instancia de TStringList que creas en ella.

Entonces podrías hacer:
Código Delphi [-]
procedure TForm1.ListaArchivos(dirPadre:string; TS: TStrings);
var
  //...
  fecha: string;
  fh: THandle;
begin
  //...
  dirPadre := IncludeTrailingPathDelimiter(dirPadre);
  if FindFirst(dirPadre + '*.*', faAnyFile, sr) = 0 then
  repeat
    //...
    if (sr.Attr and faDirectory = 0) or (sr.Name <> '.') and (sr.Name <> '..') and ( lB ) then
    begin
      fh:= FileOpen(dirPadre + sr.Name, 0);
      fecha:= DateTimeToStr(FileDateToDateTime(FileGetDate(fh)));
      TS.Add(Format('%s/%d/%s',[sr.Name, sr.Size, StringReplace(fecha,'/','-',[rfReplaceAll])]));
      FileClose(fh);
      //...
    end;
  until FindNext(sr) <> 0;
  FindClose(sr);
end;

Saludos :)

chopin_fev 29-01-2014 16:52:17

Funcion FindFirst Ayuda en Atributo Fecha
 
Gracias ecfisa, funcionó perfecto.

Saludos Cordiales.qP:-)


La franja horaria es GMT +2. Ahora son las 06:09: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