Traverse folders and subfolders

Source: Internet
Author: User

{-------------------------------------------------------------------------------
Process name: makefilelist
Author: swgweb
Date: 2007.11.25
Parameter: path, fileext: String 1. Directory to be traversed 2. File Extension to be traversed
Returned value: tstringlist

Eg: listbox1.items: = makefilelist ('e:/geek ', '.exe ');
Listbox1.items: = makefilelist ('e:/speeding up ','.*');
-------------------------------------------------------------------------------}
Function makefilelist (path, fileext: string): tstringlist;
VaR
Sch: tsearchrec;
Begin
Result: = tstringlist. Create;

If rightstr (TRIM (PATH), 1) <> '/'then
Path: = trim (PATH) + '/'
Else
Path: = trim (PATH );

If not directoryexists (PATH) then
Begin
Result. Clear;
Exit;
End;

If findfirst (path + '*', faanyfile, Sch) = 0 then
Begin
Repeat
Application. processmessages;
If (Sch. Name = '.') or (Sch. Name = '..') then continue;
If directoryexists (path + Sch. Name) then
Begin
Result. addstrings (makefilelist (path + Sch. Name, fileext ));
End
Else
Begin
If (uppercase (extractfileext (path + Sch. Name) = uppercase (fileext) or (fileext = '. *') then
Result. Add (path + Sch. Name );
End;
Until findnext (Sch) <> 0;
Sysutils. findclose (Sch );
End;
End;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.