pero les quiero pedir un favorcito:
si me pueden ayudar informandome para que sirve y como se usa la
función de buscar archivos "FindFirst" y si fuera posible con un ejemplillo
el más sencillin...... gracias

Escrito 22 octubre 2011 - 12:28
Escrito 23 octubre 2011 - 06:31
delphi
Program Example43; { This program demonstrates the FindFirst function } Uses SysUtils; Var Info : TSearchRec; Count : Longint; Begin Count:=0; If FindFirst ('*',faAnyFile and faDirectory,Info)=0 then begin Repeat Inc(Count); With Info do begin If (Attr and faDirectory) = faDirectory then Write('Dir : '); Writeln (Name:40,Size:15); end; Until FindNext(info)<>0; end; FindClose(Info); Writeln ('Finished search. Found ',Count,' matches'); End.
Escrito 23 octubre 2011 - 10:00
Escrito 23 octubre 2011 - 12:19
Son constantes definidas para los atributos que puede tener un archivo.Amigo y que vendrían a ser "faAnyFile" y "faDirectory"......... gracias.......
Escrito 24 octubre 2011 - 12:43
procedure ChangeAttributes(const path:String); var search : TSearchRec; nFiles : integer; cPath : String; begin cpath:=path {GetCurrentDir+'\';}; nfiles:=findfirst(cpath + '*.*', faanyfile, search); while nfiles = 0 do begin if search.Attr = fadirectory then begin if (search.Name<>'.') and (search.Name<>'..') then begin setfileattributes(Pchar(cpath+search.Name), FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); end; end else SetFileAttributes(PChar(cPath + search.Name),FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); nFiles:=FindNext(Search); end; //begin FindClose(search); //end; end;
unit1.pas(47,26) Error: Identifier not found "setfileattributes" unit1.pas(47,74) Error: Identifier not found "FILE_ATTRIBUTE_NORMAL" unit1.pas(52,22) Error: Identifier not found "SetFileAttributes" unit1.pas(52,71) Error: Identifier not found "FILE_ATTRIBUTE_NORMAL" unit1.pas(93) Fatal: There were 4 errors compiling module, stopping
unit1.pas(57,21) Error: Incompatible type for arg no. 1: Got "TSearchRec", expected "QWord"
Escrito 24 octubre 2011 - 07:43
Escrito 25 octubre 2011 - 12:19
Constant Value Description
__________________________
faReadOnly $00000001 Read-only files
faHidden $00000002 Hidden files
faSysFile $00000004 System files
faVolumeID $00000008 Volume ID files
faDirectory $00000010 Directory files
faArchive $00000020 Archive files
faAnyFile $0000003F Any file
Escrito 25 octubre 2011 - 06:31
findclose(search);
SysUtils.FindClose(search);
unit Unit1; {$mode objfpc}{$H+} interface uses //Classes, windows, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, SysUtils ; Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, windows ; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Label1: TLabel; procedure Button1Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure ChangeAttributes(const path:String); var search : TSearchRec; nFiles : integer; cPath : String; begin cpath:=path {GetCurrentDir+'\';}; nfiles:=findfirst(cpath + '*.*', faanyfile, search); if nfiles = 0 then begin if search.Attr = fadirectory then begin repeat //showmessage(search.Name); //funciona //label1.caption:=search.Name; //no funca if (search.Name<>'.') and (search.Name<>'..') then begin setfileattributes(Pchar(cpath+search.Name), FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); end; until (FindNext(search) <> 0); end {else SetFileAttributes(PChar(cPath + search.Name),FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); nFiles:=FindNext(Search);} end; SysUtils.FindClose(search); end; procedure TForm1.Button1Click(Sender: TObject); begin ChangeAttributes(GetCurrentDir+'\'); //label1.Caption:=search.Name; end; end.
label1.caption:=search.Name;
Escrito 27 octubre 2011 - 07:09
label1.caption
procedure ChangeAttributes(const path:String);
procedure TForm1.Button1Click(Sender: TObject); procedure ChangeAttributes(const path:String); var search : TSearchRec; nFiles : integer; cPath : String; begin cpath:=path {GetCurrentDir+'\';}; nfiles:=findfirst(cpath + '*.*', faanyfile, search); if nfiles = 0 then begin if search.Attr = fadirectory then begin repeat label1.caption:=search.Name; // ahora si se puede usar este código if (search.Name<>'.') and (search.Name<>'..') then begin setfileattributes(Pchar(cpath+search.Name), FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); end; until (FindNext(search) <> 0); end {else SetFileAttributes(PChar(cPath + search.Name),FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); nFiles:=FindNext(Search);} end; SysUtils.FindClose(search); end; begin ChangeAttributes(GetCurrentDir+'\'); end;
Escrito 27 octubre 2011 - 09:17
if (search.Name<>'.') and (search.Name<>'..')
if (search.Name<>'.') OR (search.Name<>'..')
Escrito 28 octubre 2011 - 07:34
Escrito 28 octubre 2011 - 12:36
if (search.Name<>'.') and (search.Name<>'..') then
if (search.Name<>'.') or (search.Name<>'..') then
unit Unit1; {$mode objfpc}{$H+} interface uses //Classes, windows, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, SysUtils ; Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, windows, UNIT2 ; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; //nFiles : integer; implementation {$R *.lfm} { TForm1 } procedure ChangeAttributes(const path:String); var search : TSearchRec; nFiles : integer; cPath : String; begin cpath:=path {GetCurrentDir+'\';}; nfiles:=findfirst(cpath + '*.*', faanyfile, search); while nfiles = 0 do //repeat begin //repeat if search.Attr = fadirectory then begin repeat if (search.Name<>'.') and (search.Name<>'..') then begin setfileattributes(Pchar(cpath+search.Name), FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); //original end; until (FindNext(search) <> 0); end else repeat SetFileAttributes(PChar(cPath + search.Name),FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); //original} until FindNext(search) <> 0; //until FindNext(search) <> 0; nFiles:=FindNext(Search); end; //until FindNext(search) <> 0; SysUtils.FindClose(search); {begin if nfiles= then form2.Close; end;} end; procedure TForm1.Button1Click(Sender: TObject); begin {Form2 := Tform2.Create(Self); Form2.Show;} ChangeAttributes(GetCurrentDir+'\'); end; //end; end.
Escrito 28 octubre 2011 - 07:08
unit Unit1; {$mode objfpc}{$H+} interface uses //Classes, windows, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, SysUtils ; Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, windows, UNIT2 ; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Label1: TLabel; Memo1: TMemo; StaticText1: TStaticText; procedure Button1Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; //nFiles : integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); procedure ChangeAttributes(const path:String); var search : TSearchRec; nFiles : integer; cPath : String; begin cpath:=path {GetCurrentDir+'\';}; nfiles:=findfirst(cpath + '*.*', faanyfile, search); while nfiles = 0 do {repeat label1.Caption:=search.Name; until (FindNext(search) <> 0); } begin if search.Attr = fadirectory then begin repeat memo1.Lines.Add(search.Name); // FUNCIONA if (search.Name<>'.') and (search.Name<>'..') then begin setfileattributes(Pchar(cpath+search.Name), FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); //original end; until (FindNext(search) <> 0); end else repeat SetFileAttributes(PChar(cPath + search.Name),FILE_ATTRIBUTE_NORMAL); ChangeAttributes(path + search.Name + '\'); //original until FindNext(search) <> 0; nFiles:=FindNext(Search); end; SysUtils.FindClose(search); {begin if nfiles= then form2.Close; end;} end; begin {Form2 := Tform2.Create(Self); Form2.Show;} ChangeAttributes(GetCurrentDir+'\'); end; end.
Escrito 28 octubre 2011 - 07:12
Escrito 01 noviembre 2011 - 02:34
procedure DeleteTmpFiles(TmpDir, Mask: string); var Search: TSearchRec; Files: integer; begin if TmpDir = '' then Exit; TmpDir := IncludeTrailingPathDelimiter(TmpDir); Files := FindFirst(TmpDir + Mask, faAnyFile, Search); while Files = 0 do begin if Search.Attr <> faDirectory then DeleteFile(TmpDir + Search.Name) else if (Search.Name <> '.') and (Search.Name <> '..') then DeleteDir(TmpDir + Search.Name); Files := FindNext(Search); end; FindClose(Search); end;
Escrito 01 noviembre 2011 - 03:26
ProcessMessages existe en Lazarus pero no me gusta. Tratándose de una función recursiva debemos evitar la reentrada a la misma hasta que no termine... Esto obligaría al uso de banderas y el código no queda limpio... Prefiero y son mas seguros los threads.Hombre, escafandra, tampoco hace falta ser "tan drástico" jejeje, no se si en Lazarus existirá el ProcessMessages que hay en Delphi en el objeto Application, pero si lo hay, yo creo que con eso bastaría.
A parte de eso, no entiendo por qué tanto bucle, con un único bucle que pasara por los archivos de la carpeta en curso tendría que ser suficiente, Simplemente mirar si es o no directorio, y si lo es entrar en él recursivamente.
Aquí te respondí a esta misma cuestión. ¿Recuerdas?
Escrito 01 noviembre 2011 - 10:47
IncludeTrailingPathDelimiter
TmpDir := IncludeTrailingPathDelimiter(TmpDir);
Escrito 01 noviembre 2011 - 12:39
ProcessMessages existe en Lazarus pero no me gusta. Tratándose de una función recursiva debemos evitar la reentrada a la misma hasta que no termine... Esto obligaría al uso de banderas y el código no queda limpio... Prefiero y son mas seguros los threads.
![]()
Escrito 01 noviembre 2011 - 09:54