// ==================================================== ===================== ========================
// สำรวจไฟล์ในโฟลเดอร์
// คำแนะนำสำหรับการใช้งาน
// _getFileList (listbox1.items, 'c:/*. doc');
// _getFileList (mytstringList, 'c:/*. exe');
// ==================================================== ===================== ========================
ขั้นตอน TFORM1._GetFileList (ATDRINGS: TSTRINGS; ASOURFILE: String);
var sour_path, sour_file: สตริง;
TMPLIST: TSTRINGLIST;
Filerec: TsearchRec;
เริ่ม
sour_path: = extractFilePath (asourfile);
sour_file: = extractfilename (asourfile);
ถ้าไม่ใช่ไดเรกทอรี (sour_path) แล้ว
เริ่ม
ลูกบตา
ออก;
จบ;
tmplist: = tstringlist.create;
tmplist.clear;
ถ้า findfirst (sour_path+sour_file, faanyfile, filerec) = 0 แล้ว
ทำซ้ำ
if ((filerec.attr และ fadirectory) = 0) จากนั้น
เริ่ม
tmplist.add (sour_path+filerec.name)
จบ;
จนกระทั่ง findNext (filerec) <> 0;
sysutils.findclose (filerec);
ลูกโป่ง. ASSIGN (TMPLIST);
tmplist.free;
จบ;
// ==================================================== ===================== ========================
// เดินทางผ่านโฟลเดอร์และไฟล์บางไฟล์ภายใต้โฟลเดอร์ย่อย
// คำแนะนำสำหรับการใช้งาน
// _getFileList (listbox1.items, 'c:/', '*.doc');
// _getFileList (mytstringlist, 'c:/', '*.exe');
// ==================================================== ===================== ========================
ขั้นตอน _getFileList (ATDRINGS: TSTRINGS; ASOURFILE,
ชื่อไฟล์: สตริง);
var sour_path, sour_file: สตริง;
TMPLIST: TSTRINGLIST;
filerec, subfilerec: tsearchrec;
ฉัน: จำนวนเต็ม;
เริ่ม
ถ้า rightstr (trim (asourfile), 1) <> '/' แล้ว
sour_path: = trim (asourfile) + '/'
อื่น
sour_path: = trim (asourfile);
sour_file: = ชื่อไฟล์;
ถ้าไม่ใช่ไดเรกทอรี (sour_path) แล้ว
เริ่ม
ลูกบตา
ออก;
จบ;
tmplist: = tstringlist.create;
tmplist.clear;
ถ้า findfirst (sour_path+'*.*', faanyfile, filerec) = 0 แล้ว
ทำซ้ำ
if ((filerec.attr และ fadirectory) <> 0) จากนั้น
เริ่ม
if ((filerec.name <> '.') และ (filerec.name <> '.. '))
_getFileList (ANTRINGS, sour_path + filerec.name + '/', sour_file);
จบ
อื่น
ถ้า findfirst (sour_path + ชื่อไฟล์, faanyfile, subfilerec) = 0 แล้ว
ทำซ้ำ
if ((subfilerec.attr และ fadirectory) = 0) จากนั้น
tmplist.add (sour_path+subfilerec.name);
จนกระทั่ง findNext (subfilerec) <> 0;
จนกระทั่ง findNext (filerec) <> 0;
sysutils.findclose (filerec);
สำหรับ i: = 0 ถึง tmplist.count -1 ทำ
ANTRINGS.ADD (tMplist.strings [i]);
tmplist.free;
จบ;