Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 29-10-2007
Patho Patho is offline
Registrado
 
Registrado: oct 2007
Posts: 6
Poder: 0
Patho Va por buen camino
TFileListBox archivos *.txt con meses

amigos recurro a ustedes nuevamente, tengo un TFileListBox rescatando archivos *.txt y son meses todo funciona bastante bien, pero ahora me han pedido que lo ordenes segun los meses correspondiente, cada archivo corresponde a cada mes del año y necesito ordenarlo por mes, se puede hacer esto con el TFileListBox ??? o sino para utilizar otra manera, de ante mano muchas gracias


saludos

Patho
Responder Con Cita
  #2  
Antiguo 29-10-2007
Northern Northern is offline
Miembro
 
Registrado: ene 2006
Posts: 211
Poder: 19
Northern Va por buen camino
Aquí http://216.101.185.148/scripts/isapi...rticle=1502193

aquí http://216.101.185.148/scripts/isapi...rticle=1502242

y aquí http://216.101.185.148/scripts/isapi...rticle=1502249


tienes como se puede hacer (ordenando por fecha y por último acceso) sin usar TFileListBox ya que este control no incorpora ordenar archivos por alguno de sus atributos.


Saludos
Responder Con Cita
  #3  
Antiguo 29-10-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
ixMike Va por buen camino
Bueno, amigo Northern, creo que a lo que Patho se refiere es a que los archivos se llaman ener.txt, febrero.txt, marzo.txt... (si no es así, por favor, corrígeme). En ese caso, para ordenarlos, no veo una solución directa.

Podrías renombrar los archivos, de la siguiente manera: "01enero.txt", "02febrero.txt"... así se ordenarían automáticamente por nombre.

También podrías utilizar un TListBox normal, y los métedos FindFirst y FindNext para añadirle los archiovos. Así podrías manejar los Items del TListBox a tu gusto.

Saludos.
Responder Con Cita
  #4  
Antiguo 29-10-2007
Northern Northern is offline
Miembro
 
Registrado: ene 2006
Posts: 211
Poder: 19
Northern Va por buen camino
Cita:
Empezado por ixMike Ver Mensaje
Bueno, amigo Northern, creo que a lo que Patho se refiere es a que los archivos se llaman ener.txt, febrero.txt, marzo.txt... (si no es así, por favor, corrígeme). En ese caso, para ordenarlos, no veo una solución directa.

......

Puedes ir llamando a la función GetAllFiles especificando el mes GetAllFiles(FileList, 'ene*.*', faArchive);etc.


Y como acabo de entrar y me he dado cuenta de que los enlaces que puse hacia www.tamaracka.comvan por tiempo pongo aquí los códigos pero que sepas que están sacados de allí:

Código Delphi [-]
type
  { New type of TStringList which can sort ascending and
    descending. It is specialized in sorting on filedates
    which are/must be stored in the objects part of the list}
  TNewStringList = class(TStringList)
  private
    FSortDir : integer;
  protected
    function CompareFileDates(Idx1, Idx2: integer): integer;
    procedure BSort(L, R: integer);
  public
    procedure Sort; override;
    property SortDir: integer read FSortDir write FSortDir default 0;
  end;

{ TNewStringList }
function TNewStringList.CompareFileDates(Idx1, Idx2: integer): integer;
begin
  if integer(Objects[Idx1]) > integer(Objects[Idx2]) then
    Result := 1
  else if integer(Objects[Idx1]) < integer(Objects[Idx2]) then
    Result := -1
  else
    Result := 0;
end;

{It's not the fastest sorting algorithm but I couldn't get
the quicksort to function with it at the moment}
procedure TNewStringList.BSort(L, R: integer);
var
  I, P : integer;
begin
  if SortDir = 0 then // ascending
  begin
    repeat
      P := L;
      for I := L to R do
        if CompareFileDates( I, P ) > 0 then
          P := I;
      if P <> R then
        Exchange(P, R);
      Dec(R);
    until R <= L;
  end
  else // descending
  begin
    repeat
      P := L;
      for I := L to R do
        if CompareFileDates( I, P ) < 0 then
          P := I;
      if P <> R then
        Exchange(P, R);
      Dec(R);
    until R <= L
  end;
end;

procedure TNewStringList.Sort;
begin
  if not Sorted and (Count > 1) then
  begin
    Changing;
    BSort(0, Count - 1);
    Changed;
  end;
end;

procedure GetAllFiles(Items: TStrings; SearchSpecs: string; Attr: word);
var
  SearchRec: TSearchRec;
begin
  if FindFirst(SearchSpecs, faAnyFile, SearchRec)=0 then
    repeat
      if (SearchRec.Name <> '.') and
         (SearchRec.Name <> '..') and
         ((SearchRec.Attr and Attr) <> 0) then
        Items.AddObject(SearchRec.Name, TObject(SearchRec.Time));
    until FindNext(SearchRec) <> 0;
  FindClose(SearchRec);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Cnt : integer;
  FileList : TNewStringList;
  ADateTime : TDateTime;
begin
  FileList := TNewStringList.Create;
  try
    GetAllFiles(FileList, '*.*', faArchive);
    FileList.SortDir := 1; // 0=ascending 1=descending
    FileList.Sort;

    Memo1.Clear;
    for Cnt := 0 to FileList.Count-1 do
    begin
      ADateTime := FileDateToDateTime(integer(FileList.Objects[Cnt]));
      Memo1.Lines.Add(
        Format('%-20s %20s', [FileList[Cnt],
FormatDateTime('c',ADateTime)]));
    end;
  finally
    FileList.Free;
  end;
end;


Saludos
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
Directorios con TFileListBox Drake C++ Builder 2 03-09-2006 16:15:19
TFileListBox fjcg02 OOP 4 04-04-2006 17:25:19
Dias y meses romansiux Varios 5 13-06-2005 17:19:12
existe algo similar a TFileListBox para Http? miguel_fr Internet 1 14-04-2004 06:15:35
Tfilelistbox Un abrazo OOP 2 15-05-2003 16:46:33


La franja horaria es GMT +2. Ahora son las 14:58:36.


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