Search This Blog

Saturday, June 21, 2008

Scanning a folder in Borland Delphi

Here is a readymade procedure for scanning a folder and applying some action on each subfolder or file


procedure ScanFolder( src string );
var
sts : Integer ;
SR: TSearchRec;
begin
sts := FindFirst( src + '*.*' , faAnyFile , SR );
if sts = 0 then
begin
if ( SR.Name <> '.' ) and ( SR.Name <> '..' ) then
begin
//Put User Feedback here if desired
Application.ProcessMessages;
if pos('.', SR.Name) = 0 then
begin
//subfolder put your code for subfolder
scanFolder(src + SR.Name);
end
else
//file put your code for file
end;
while FindNext( SR ) = 0 do
begin
if ( SR.Name <> '.' ) and ( SR.Name <> '..' ) then
begin
//Put User Feedback here if desired
Application.ProcessMessages;
if Pos('.', SR.Name) = 0 then
begin
//subfolder put your code for subfolder
scanFolder(src + SR.Name);
end
else
//file put your code for file
end;
end;
FindClose( SR ) ;
end ;
end;

No comments:

Post a Comment

Searching duplicate Record

Very often we have to look for duplicate records in the database, Below is the query which can give you the result. SELECT COL1, COL2 , ...