Bueno pues use la funcion de neftali:
Código Delphi
[-] procedure FindFiles(StartDir, FileMask: string; recursively: boolean; var FilesList: TStringList);
const
MASK_ALL_FILES = '*.*';
CHAR_POINT = '.';
var
SR: TSearchRec;
DirList: TStringList;
IsFound: Boolean;
i: integer;
begin
if (StartDir[length(StartDir)] <> '\') then begin
StartDir := StartDir + '\';
end;
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, SR) = 0;
while IsFound do begin
FilesList.Add(StartDir + SR.Name);
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
if (recursively) then begin
DirList := TStringList.Create;
try
IsFound := FindFirst(StartDir + MASK_ALL_FILES, faAnyFile, SR) = 0;
while IsFound do
begin
if ((SR.Attr and faDirectory) <> 0) and
(SR.Name[1] <> CHAR_POINT) then
DirList.Add(StartDir + SR.Name);
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
for i := 0 to DirList.Count - 1 do
FindFiles(DirList[i], FileMask, recursively, FilesList);
finally
DirList.Free;
end;
end;
end;
Ahora bien mi aplicacion de terminal de puesto de venta tiene un modulo con un edit con la cantidad de ticket(1 por archivo) y un progress bar para programar despues.
El caso es que en el evento OnShow del form llamo a
Código Delphi
[-]procedure TForm10.FormShow(Sender: TObject);
var
StartDir, FileMask: string;
recursively: boolean;
FilesList: TStringList;
x,cant:integer;
begin
StartDir:=ExtractFilePath(Application.ExeName) + 'tickets';
FindFiles(StartDir, FileMask, recursively, FilesList);
end;
pasandole los parametros Stardir, pero debo crear el objeto fileslist?
Luego debo agregar obviamente el codigo que quiero se ejecute al encontrar un archivo dentro del while.
Código Delphi
[-]procedure FindFiles(StartDir, FileMask: string; recursively: boolean; var FilesList: TStringList);
const
MASK_ALL_FILES = '*.*';
CHAR_POINT = '.';
var
SR: TSearchRec;
DirList: TStringList;
IsFound: Boolean;
i,x: integer;
a:TServerMethods1Client;
l:integer;
fechae,horae,nombrearchivo,nombrecopia:string;
cantidad,importe,preciou,efectivo,vueltoouble;
idc,ids,idprodu,numero:Integer;
nuevoticket:string;
begin
if (StartDir[length(StartDir)] <> '\') then begin
StartDir := StartDir + '\';
end;
FilesList.Create;
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, SR) = 0;
while IsFound do begin
FilesList.Add(StartDir + SR.Name);
IsFound := FindNext(SR) = 0;
end;
if FilesList.Count<>0 then
begin
for x:=FilesList.Count - 1 downto 0 do
begin
Form10.Etick.Text:=IntToStr(FilesList.Count);
nombrearchivo:=SR.Name;
ShowMessage(nombrearchivo);
ClientModule1.cdsticketpendiente.LoadFromFile(nombrearchivo);
nombrecopia:=ExtractFileName(Application.ExeName) + 'ticketscopia\' + nombrearchivo;
CopyFile(Pchar(nombrearchivo),Pchar(nombrecopia),True);
idc:=1;
ids:=1;
numero:=1;
importe:=ClientModule1.cdsticketpendiente.FieldByName('total').Value;
fechae:=ClientModule1.cdsticketpendientefechae.AsString;
horae:=ClientModule1.cdsticketpendientehorae.AsString;
efectivo:=ClientModule1.cdsticketpendienteefectivo.AsFloat;
vuelto:=efectivo - importe;
a.nuevoticket(numero,ids,idc,importe,efectivo,vuelto,fechae,horae);
end;
end;
FilesList.Destroy;
if (recursively) then begin
DirList := TStringList.Create;
try
IsFound := FindFirst(StartDir + MASK_ALL_FILES, faAnyFile, SR) = 0;
while IsFound do
begin
if ((SR.Attr and faDirectory) <> 0) and
(SR.Name[1] <> CHAR_POINT) then
DirList.Add(StartDir + SR.Name);
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
for i := 0 to DirList.Count - 1 do
FindFiles(DirList[i], FileMask, recursively, FilesList);
finally
DirList.Free;
end;
end;
end;