it has been 4 hours now, and im trying to code it
every time i code it it don't search Subfolders,im trying to make it a Function not a Button Click that searches files, but a function i call searches the files and i get the result then i display it in a listview
like
[code]
function SearchFiles(const strPath: String;strSearchFor:String): String;
[/code]
and the result string will be
[code]
Result := Result + FileName + '|' + FileDirectory + '|' + File Type + '|' + FileSize + '|';
[/code]
can anybody help plz
i know there is some GREAT PROGRAMMERS here
i hope anyone of them have the time to help
Comments
: every time i code it it don't search Subfolders,im trying to make it
: a Function not a Button Click that searches files, but a function i
: call searches the files and i get the result then i display it in a
: listview
: like
: [code]:
: function SearchFiles(const strPath: String;strSearchFor:String): String;
: [/code]:
: and the result string will be
: [code]:
: Result := Result + FileName + '|' + FileDirectory + '|' + File Type + '|' + FileSize + '|';
: [/code]:
:
: can anybody help plz
: i know there is some GREAT PROGRAMMERS here
: i hope anyone of them have the time to help
:
Here's a code, which searches through a subtree of directories and places the results in a TStrings object:
[code]
procedure SearchFiles(const strPath: String;strSearchFor:String; Results: TStrings);
var
SR: TSearchRec;
begin
if FindFirst(strPath+'*.*', faAnyFile, SR) = 0 then repeat
if ((SR.Attributes and faDirectory) = faDirectory) and // filter subdirs
(SR.Filename[1] <> '.') then // filter current and parent dir
SearchFiles(IncludeTrailingBackSlash(strPath+SR.Filename), strSearchFor, Results)
else if Pos(Uppercase(strSearchFor), Uppercase(SR.Filename)) > 0 then
with SR do
Results.add(FileName + '|' + strPath+ '|' + IntToStr(integer(Attributes)) + '|' + IntToStr(Size)+ '|';
until FindNext(SR) <> 0;
FindClose(SR);
end;
[/code]
When calling this function it is important that the strPath includes the trailing backslash. All the functions, types and constants are listed in the help files. I'm not sure about the some of the names of the TSearchRec fields, so check that out first.
: : every time i code it it don't search Subfolders,im trying to make it
: : a Function not a Button Click that searches files, but a function i
: : call searches the files and i get the result then i display it in a
: : listview
: : like
: : [code]: :
: : function SearchFiles(const strPath: String;strSearchFor:String): String;
: : [/code]: :
: : and the result string will be
: : [code]: :
: : Result := Result + FileName + '|' + FileDirectory + '|' + File Type + '|' + FileSize + '|';
: : [/code]: :
: :
: : can anybody help plz
: : i know there is some GREAT PROGRAMMERS here
: : i hope anyone of them have the time to help
: :
: Here's a code, which searches through a subtree of directories and
: places the results in a TStrings object:
: [code]:
: procedure SearchFiles(const strPath: String;strSearchFor:String; Results: TStrings);
: var
: SR: TSearchRec;
: begin
: if FindFirst(strPath+'*.*', faAnyFile, SR) = 0 then repeat
: if ((SR.Attributes and faDirectory) = faDirectory) and // filter subdirs
: (SR.Filename[1] <> '.') then // filter current and parent dir
: SearchFiles(IncludeTrailingBackSlash(strPath+SR.Filename), strSearchFor, Results)
: else if Pos(Uppercase(strSearchFor), Uppercase(SR.Filename)) > 0 then
: with SR do
: Results.add(FileName + '|' + strPath+ '|' + IntToStr(integer(Attributes)) + '|' + IntToStr(Size)+ '|';
: until FindNext(SR) <> 0;
: FindClose(SR);
: end;
: [/code]:
: When calling this function it is important that the strPath includes
: the trailing backslash. All the functions, types and constants are
: listed in the help files. I'm not sure about the some of the names
: of the TSearchRec fields, so check that out first.
thanks man
but it's not working, can't compile
i tried to define it
[code]
type
TSearchRec = record
Time: Integer;
Size: Integer;
Attr: Integer;
Name: TFileName;
ExcludeAttr: Integer;
FindHandle: THandle;
FindData: TWin32FindData;
end;
[/code]
can u try to compile it on ur pc and test it
thanks again, i really appreciate your help
: : : every time i code it it don't search Subfolders,im trying to make it
: : : a Function not a Button Click that searches files, but a function i
: : : call searches the files and i get the result then i display it in a
: : : listview
: : : like
: : : [code]: : :
: : : function SearchFiles(const strPath: String;strSearchFor:String): String;
: : : [/code]: : :
: : : and the result string will be
: : : [code]: : :
: : : Result := Result + FileName + '|' + FileDirectory + '|' + File Type + '|' + FileSize + '|';
: : : [/code]: : :
: : :
: : : can anybody help plz
: : : i know there is some GREAT PROGRAMMERS here
: : : i hope anyone of them have the time to help
: : :
: : Here's a code, which searches through a subtree of directories and
: : places the results in a TStrings object:
: : [code]: :
: : procedure SearchFiles(const strPath: String;strSearchFor:String; Results: TStrings);
: : var
: : SR: TSearchRec;
: : begin
: : if FindFirst(strPath+'*.*', faAnyFile, SR) = 0 then repeat
: : if ((SR.Attributes and faDirectory) = faDirectory) and // filter subdirs
: : (SR.Filename[1] <> '.') then // filter current and parent dir
: : SearchFiles(IncludeTrailingBackSlash(strPath+SR.Filename), strSearchFor, Results)
: : else if Pos(Uppercase(strSearchFor), Uppercase(SR.Filename)) > 0 then
: : with SR do
: : Results.add(FileName + '|' + strPath+ '|' + IntToStr(integer(Attributes)) + '|' + IntToStr(Size)+ '|';
: : until FindNext(SR) <> 0;
: : FindClose(SR);
: : end;
: : [/code]: :
: : When calling this function it is important that the strPath includes
: : the trailing backslash. All the functions, types and constants are
: : listed in the help files. I'm not sure about the some of the names
: : of the TSearchRec fields, so check that out first.
:
: thanks man
: but it's not working, can't compile
: i tried to define it
: [code]:
: type
: TSearchRec = record
: Time: Integer;
: Size: Integer;
: Attr: Integer;
: Name: TFileName;
: ExcludeAttr: Integer;
: FindHandle: THandle;
: FindData: TWin32FindData;
: end;
: [/code]:
:
: can u try to compile it on ur pc and test it
: thanks again, i really appreciate your help
:
:
Everything in this code is already defined in the various standard units of Delphi. I don't have Delphi here, but I think TSearchRec is in the Windows unit; FindFirst(), FindNext(), FindClose(), IncludeTrailingBackSlash(), Uppercase() are in the SysUtils; TStrings in Classes.
The helpfile files list the unit in which all the types and functions are defined. Just place the textcursor on a word and press F1 to open the help files.
[code]
Function SearchFiles(const strPath: String;strSearchFor:String;Results: TStrings):String;
var
SR: TSearchRec;
begin
if FindFirst(strPath+'*.*', faAnyFile, SR) = 0 then repeat
if ((SR.Attr and faDirectory) = faDirectory) and // filter subdirs
(SR.Name[1] <> '.') then // filter current and parent dir
SearchFiles(IncludeTrailingBackSlash(strPath+SR.Name), strSearchFor, Results)
else if Pos(Uppercase(strSearchFor), Uppercase(SR.name)) > 0 then
with SR do
Results.add(Name + '|' + strPath + '|' + IntToStr(integer(Attr)) + '|' + IntToStr(Size)+ '|');
until FindNext(SR) <> 0;
FindClose(SR);
end;
[/code]
you and me just missed some stuff like "SR.Attributes" insted of "SR.Attr", some small stuff
but i dunno how to get the result and add it to listview??
can you??
i know im greedy
thank u man for your help
:
: [code]:
: Function SearchFiles(const strPath: String;strSearchFor:String;Results: TStrings):String;
: var
: SR: TSearchRec;
: begin
: if FindFirst(strPath+'*.*', faAnyFile, SR) = 0 then repeat
: if ((SR.Attr and faDirectory) = faDirectory) and // filter subdirs
: (SR.Name[1] <> '.') then // filter current and parent dir
: SearchFiles(IncludeTrailingBackSlash(strPath+SR.Name), strSearchFor, Results)
: else if Pos(Uppercase(strSearchFor), Uppercase(SR.name)) > 0 then
: with SR do
: Results.add(Name + '|' + strPath + '|' + IntToStr(integer(Attr)) + '|' + IntToStr(Size)+ '|');
: until FindNext(SR) <> 0;
: FindClose(SR);
: end;
: [/code]:
:
: you and me just missed some stuff like "SR.Attributes" insted of
: "SR.Attr", some small stuff
:
: but i dunno how to get the result and add it to listview??
: can you??
:
: i know im greedy
: thank u man for your help
:
:
First create a temporary TStringList to hold all the items and get the results into it:
[code]
var
Results: TStrings;
begin
Results := TStringList.Create();
SearchFiles('SomePath', '.txt', Results);
[/code]
Now Results holds all the requested info from SomePath and its subfolders (.txt files in this code). Now you can copy the requested info into a listview:
[code]
ListView1.Items.Clear;
if Results.Count > 0 then
for i := 0 to Results.Count-1 do
with ListView1.Items.Add do begin
Caption := Results[i];
end;
[/code]
: :
: : [code]: :
: : Function SearchFiles(const strPath: String;strSearchFor:String;Results: TStrings):String;
: : var
: : SR: TSearchRec;
: : begin
: : if FindFirst(strPath+'*.*', faAnyFile, SR) = 0 then repeat
: : if ((SR.Attr and faDirectory) = faDirectory) and // filter subdirs
: : (SR.Name[1] <> '.') then // filter current and parent dir
: : SearchFiles(IncludeTrailingBackSlash(strPath+SR.Name), strSearchFor, Results)
: : else if Pos(Uppercase(strSearchFor), Uppercase(SR.name)) > 0 then
: : with SR do
: : Results.add(Name + '|' + strPath + '|' + IntToStr(integer(Attr)) + '|' + IntToStr(Size)+ '|');
: : until FindNext(SR) <> 0;
: : FindClose(SR);
: : end;
: : [/code]: :
: :
: : you and me just missed some stuff like "SR.Attributes" insted of
: : "SR.Attr", some small stuff
: :
: : but i dunno how to get the result and add it to listview??
: : can you??
: :
: : i know im greedy
: : thank u man for your help
: :
: :
: First create a temporary TStringList to hold all the items and get
: the results into it:
: [code]:
: var
: Results: TStrings;
: begin
: Results := TStringList.Create();
: SearchFiles('SomePath', '.txt', Results);
: [/code]:
: Now Results holds all the requested info from SomePath and its
: subfolders (.txt files in this code). Now you can copy the requested
: info into a listview:
: [code]:
: ListView1.Items.Clear;
: if Results.Count > 0 then
: for i := 0 to Results.Count-1 do
: with ListView1.Items.Add do begin
: Caption := Results[i];
: end;
: [/code]:
thank you so much
it's working, even if it's listing all results on one column, i will try to fix that
anyway
if u need anything just tell me, i got all the versions of delphi (from 5 to 2007) i can upload anyone u want to rapidshare.de so u can download them
find -r -n "*" "C:/whateverfolder" ($ftype=="f")
will show you all the files. For free download http://www.biterscripting.com .