Hi,
I have a function that has worked quite well in Windows. Now I try to use it
on Linux and it does not appear to be going into subdirectories where the files
are actually stored. The unit is below. I use the following
FindFile1.Filemask:='*.cfg';
FindFile1.InSubFolders:=True;
FindFile.Path:='/test/sup/Data';
Now in Data there are other directories where the .cfg files reside. I do not
know what these directories are since they are created at design time. The
program seems to work ok when I give it the exact path but does not when it has
to search in sub folders. That is why I had to turn it to true. If anyone knows
what is wrong or has another solution that would be great. Thanks
unit FindFile;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FileCtrl;
type TFileAttrKind = (ffaReadOnly, ffaHidden, ffaSysFile, ffaVolumeID,
ffaDirectory, ffaArchive, ffaAnyFile); TFileAttr = set of TFileAttrKind;
TFindFile = class(TComponent) private s : TStringList;
fSubFolder : boolean; fAttr: TFileAttr; fPath : string; fFileMask
: string;
procedure SetPath(Value: string); procedure FileSearch(const inPath :
string); public constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function SearchForFiles: TStringList; published property FileAttr:
TFileAttr read fAttr write fAttr; property InSubFolders : boolean read
fSubFolder write fSubFolder; property Path : string read fPath write
SetPath; property FileMask : string read fFileMask write fFileMask ; end;
procedure Register;
implementation
procedure Register;begin RegisterComponents('About.com', [TFindFile]);end;
constructor TFindFile.Create(AOwner: TComponent);begin inherited
Create(AOwner); Path := IncludeTrailingBackslash(GetCurrentDir); FileMask :=
'*.*'; FileAttr := [ffaAnyFile]; s := TStringList.Create;end;
destructor TFindFile.Destroy;begin s.Free; inherited Destroy;end;
procedure TFindFile.SetPath(Value: string);begin if fPath <> Value then begin
if Value <> '' then if DirectoryExists(Value) then fPath :=
IncludeTrailingBackslash(Value); end;end;
function TFindFile.SearchForFiles: TStringList;begin s.Clear; try
FileSearch(Path); finally Result := s; end;end;
procedure TFindFile.FileSearch(const InPath : string);var Rec : TSearchRec;
Attr : integer;beginAttr := 0;if ffaReadOnly in FileAttr then Attr := Attr +
faReadOnly;if ffaHidden in FileAttr then Attr := Attr + faHidden;if ffaSysFile
in FileAttr then Attr := Attr + faSysFile;if ffaVolumeID in FileAttr then Attr
:= Attr + faVolumeID;if ffaDirectory in FileAttr then Attr := Attr +
faDirectory;if ffaArchive in FileAttr then Attr := Attr + faArchive;if
ffaAnyFile in FileAttr then Attr := Attr + faAnyFile;
if SysUtils.FindFirst(inPath + FileMask, Attr, Rec) = 0 then try repeat
s.Add(inPath + Rec.Name); until SysUtils.FindNext(Rec) <> 0; finally
SysUtils.FindClose(Rec); end;
If not InSubFolders then Exit;
if SysUtils.FindFirst(inPath + '*.*', faDirectory, Rec) = 0 then try repeat
if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..')
then begin FileSearch(IncludeTrailingBackslash(inPath + Rec.Name));
end; until SysUtils.FindNext(Rec) <> 0; finally SysUtils.FindClose(Rec);
end;end;
end._______________________________________________
Lazarus mailing list
[email protected]
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus