Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
If all you want is to obtain a list of subdirectories within a specified path, you can use FindFirst/FindNext as in the following code:
procedure Form1.GetDirList(sPath: string); var Found: Integer; SearchRec: TSearchRec; begin Found := SysUtils.FindFirst(IncludeTrailingBackslash(sPath) + '*.*', faDirectory, SearchRec); try while Found = 0 do begin if ((SearchRec.Attr and faDirectory) = faDirectory) and (SearchRec.Name[1] <> '.') then ListBox1.Items.Add(SearchRec.Name); Found := SysUtils.FindNext(SearchRec); end; finally SysUtils.FindClose(SearchRec); end; end;
However, if you want to get the subdirectories within a specified path AND the subdirectories under those, then you need to use a recursive procedure. A recursive procedure (or function) is one that calls itself. (NOTE: The most important thing to remember when creating recursive methods is to make sure there is some condition to exit from the method at some point!) Here is a procedure that will obtain all subdirectories from a specified path down:
procedure Form1.GetSubDirList(sPath: string); var Found: Integer; SearchRec: TSearchRec; begin Found := SysUtils.FindFirst(IncludeTrailingBackslash(sPath) + '*.*', faDirectory, SearchRec); try while Found = 0 do begin if ((SearchRec.Attr and faDirectory) = faDirectory) and (SearchRec.Name[1] <> '.') then begin ListBox1.Items.Add(IncludeTrailingBackslash(sPath) + SearchRec.Name); Application.ProcessMessages; // Recursive method call GetSubDirList(IncludeTrailingBackslash(sPath) + SearchRec.Name); end; Found := SysUtils.FindNext(SearchRec); end; finally SysUtils.FindClose(SearchRec); end; end;
A while back there was an article, some forum discussion, and a free component for extending the functionality of FindFirst and FindNext at Old UBB Archived Link: [URL=http://delphi.about.com/]http://delphi.about.com/[/URL]
Rick Carter Chair, Delphi/Paradox SIG Cincinnati PC Users Group
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
We use code that is very similiar to this, but we don't call Application.ProcessMessages. What is the benefit of making that call here? Is it advisable to do this before making a recursive call, and if so, why?
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
The recursive call to GetSubDirList doesn't trigger the Windows Event Handler until it returns from the last call. So "Application.ProcessMessages" triggers the event handler to repaint the lines in the list box as they are being written.
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.