Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 883015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:31:03+00:00 2026-05-15T12:31:03+00:00

I’m encountering a big problem when i’m trying to make a recursive search function

  • 0

I’m encountering a big problem when i’m trying to make a recursive search function inside a thread (using delphi 7) bellow is the code:

TParcFicDir = class(TThread)
private
 several variables..
 protected
    procedure Execute; override;
  public
    constructor Create(CreateSuspended: Boolean);


constructor TParcFicDir.Create(CreateSuspended: Boolean);
begin
 inherited Create(CreateSuspended);
end;

procedure TParcFicDir.Execute;
begin
 try
  FindFiles(FStartDir,FMask);//'c:\' and '*.*'
 except on e:Exception do
 end;
end;

procedure TParcFicDir.FindFiles(StartDir, FileMask: string);
var
  wTmp              : string;
  f:TextFile;
  wTempSR:TSearchRec;

  function Search(StartDir, FileMask: string): string;
  var
    SR              : TSearchRec;
    IsFound         : Boolean;
    files           : integer;
    dirs            : integer;
    t               : string;
  begin
    try
      files := 0;
      dirs := 0;
      if StartDir[length(StartDir)] <> '\' then
        StartDir := StartDir + '\';
      try
        IsFound := (FindFirst(StartDir + '*.*', faAnyFile, SR) = 0);// here the thread gets interrupted
      except on e: Exception do
      end;
      while IsFound do
      begin
        if (SR.Name <> '.') and (SR.Name <> '..') then
          if ((SR.Attr and faDirectory) <> 0) then
          if FScanDirs then 
          begin
            inc(dirs);
            t := Search(StartDir + SR.Name, FileMask);
            try
              files := files + strtoint(copy((t), 0, pos('#', t) - 1));//old code, don't take on calcul;
              Delete(t, 1, pos('#', t));
              dirs := dirs + strtoint(t);
            except on e: Exception do
            end;
            begin
              t := StartDir + SR.Name;
              wTmp := t;
              wtmp := '';
              Inc(FDirNo);
              writeln(f,t);
              inc(filno);
            end;
          end
          else
          if ScanFiles then 
          begin
           inc(filno);
           inc(files);
          end;
        IsFound := FindNext(SR) = 0;
      end;
      Result := IntToStr(files) + '#' + IntToStr(dirs);
      sysutils.FindClose(SR);
    except on e: Exception do
    end;
  end;
begin
 filno := 0;
  try
    try
      if trim(FPathFileTmp)<>'' then
       AssignFile(f, FPathFileTmp+'Temp.bak')
      else
       AssignFile(f,ExtractFileDir(GetDllName)+'\Temp.bak');
      Rewrite(f);
      Search(StartDir, FileMask);
      if StartDir[length(StartDir)] = '\' then
        delete(StartDir, length(StartDir), 1);
      wTmp := StartDir;
      wTmp := '';
      if FindFirst(StartDir, faDirectory, wTempSR) = 0 then
      writeln(f);
      writeln(f);
      CloseFile(f);
    except on e: Exception do
    end;
  finally
  end;
end;

ok, probably the code is a little messed up, but i don’t understand why the thread ends at ‘findfirst’ part….i googled it, no results.

any help will be appreciated!

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:31:04+00:00Added an answer on May 15, 2026 at 12:31 pm

    In your posted code I see that you try catch and forget the exception. When you have broken code that contains something like that, the very first thing I do is remove the empty except block. Odds are that don’t know what is going on because your throwing the information you need away.

    You have two calls to FindFirst() in your code. The usage of the one where your trying to find a directory is suspect. I would change your code to something like this.

    var
     SR : TSearchRec;
    
    begin
      if FindFirst('C:\',faDirectory,SR) <> 0 then
         RaiseLastOSError;
    end;
    

    Then you will see the reason FindFirst() Failed.

    Instead of using FindFirst() in the case where your looking for the directory I would use the DirectoryExists() call instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 429k
  • Answers 429k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In that case they return the same and there's no… May 15, 2026 at 1:40 pm
  • Editorial Team
    Editorial Team added an answer Bluetooth service classes are standardized. Depending on which bits are… May 15, 2026 at 1:40 pm
  • Editorial Team
    Editorial Team added an answer In a fixed-width destination (even though it's "text") - it's… May 15, 2026 at 1:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.