Recursive Algorithms for traversing all files in a folder in Delphi

Source: Internet
Author: User
{----------------------------------------------------------------------------- Process name: makefilelist traversal folder and subfolders parameter: path, fileext: String 1. directory to be traversed 2. the returned value of the file extension to be traversed: tstringlistuse strutils eg: listbox1.items: = makefilelist ('e: \ geipifly', '.exe '); listbox1.items: = makefilelist ','. * '); Comment} function makefilelist (path, fileext: string): tstringlist; varsch: tsearchrec; beginresult: = tstringlist. create; If rightstr (TRIM (PATH), 1) <> '\' Then path: = trim (PATH) + '\' else path: = trim (PATH ); if not directoryexists (PATH) thenbegin result. clear; exit; end; If findfirst (path + '*', faanyfile, Sch) = 0 thenbegin 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;

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.