Two Delphi traverses the function of specifying type files in the specified directory

xiaoxiao2021-03-06  81

By Meiqingsong (Affei)

/ / =========================================================================================================================================================================================== ================ // Travers a file, // use the instructions //  _GetFileList (ListBox1.Items, 'C: / *. Doc' ); // _GetFileList (MytstringList, 'c: / *. EXE'); // ============================== ============================================================== Sour_file: string; tmplist: tstringlist; fib: tsearchrec; begin

Sour_path: = extractfilepath (asseorfile); Sour_file: = extractFileName (asourfile);

IF not directoryexists (SOUR_PATH) THEN BEGIN Astrings.clear; EXIT;

TMPList: = TSTRINGLIST.CREATE; TMPList.clear;

if FindFirst (sour_path sour_file, faAnyfile, FileRec) = 0 then repeat if ((FileRec.Attr and faDirectory) = 0) then begin TmpList.Add (sour_path FileRec.Name) end; until FindNext (FileRec) <> 0;

Sysutils.FindClose (fileEREC);

Astrings.assign (TMPLIST);

TMPList.Free; end;

/ / =========================================================================================================================================================================================== ================ // Travers a folder and subfolder under some kind of file, // Use //  _GetFileList (listbox1.items, 'C: / ',' * .doc '); // _GetFileList (MytstringList,' c: / ',' * .exe '); // ===================== ================================================================================================================================ gTFileList (Astrings: Tstrings ; ASourFile, FileName: string); var sour_path, sour_file: string; TmpList: TStringList; FileRec, subFileRec: TSearchrec; i: Integer; begin if rightStr (trim (ASourFile), 1) <> '/' then sour_path: = trim (Asourfile) '/' Else Sour_path: = trim (asseourfile); Sour_file: = filename; if not directoryexists (SOUR_PATH) THEN BEGIN Astrings.clear; End;

TMPList: = TSTRINGLIST.CREATE; TMPList.clear;

If FindFirst (SOUR_PATH '*. *', FAANYFILE, FileREC) = 0 THEN REPEAT IF ((FileRec.ttr and fadirectory <> 0) THEN BEGIN IF ((FileRec.name <> ') and (fileRec.name <> '..')) then _GetFileList (AStrings, sour_path FileRec.Name '/', sour_file); end else if FindFirst (sour_path FileName, faAnyfile, subFileRec) = 0 then repeat if ((subFileRec.Attr and faDirectory ) = 0) THEN TMPLIST.ADD (SOUR_PATH SUBFILEREC.NAME); Until FindNext (SubfileRec) <> 0; Until FindNext (FileRec) <> 0;

Sysutils.FindClose (FileRec); for i: = 0 to tmplist.count -1 do assenging.add (tmplist.strings [i]);

TMPList.Free; end;

转载请注明原文地址:https://www.9cbs.com/read-94865.html

New Post(0)