要是不用Memo这个控件,ShowMessage(文件名),能成立不?
本帖最后由 冥界3大法王 于 2022-6-15 12:05 编辑uses strUtils;
procedure FindFiles(FilesList: TStrings; Subdir: Boolean; StartDir, FileMask: string);
var
SR: TSearchRec;
DirList, DirlistOnly: TStringList;
IsFound: Boolean;
i, Count: integer;
begin
if StartDir <> '\' then
StartDir := StartDir + '\';
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, SR) = 0;
while IsFound do
begin
begin
FilesList.Add(StartDir + SR.Name);
Count := Count + SR.Size;
end;
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
// Build a list of subdirectories
DirList := TStringList.Create;
IsFound := FindFirst(StartDir + '*.*', faAnyFile, SR) = 0;
while IsFound do
begin
if ((SR.Attr and faDirectory) <> 0) and (SR.Name <> '.') and (Subdir = true) and (SR.name <> '..') then
begin
DirList.Add(StartDir + SR.Name);
end;
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
// Scan the list of subdirectories
for i := 0 to DirList.Count - 1 do
begin
FindFiles(FilesList, Subdir, DirList, FileMask);
end;
DirList.Free;
end;
procedure TForm4.Button16Click(Sender: TObject);
begin
FindFiles(Memo1.Lines, false, 'X:\输出工具', '*.dcu');
end;
var
sFile:TextFile;
Memo控件里的内容,用sFile赋值应该可以 能肯定是能,就是改动比较大, 想改的少点,直接FilesList1: TStrings 用 FilesList1 替换 Memo1.Lines 最后用 for str1 in FilesList1 doshowmeessage(str1);
但整体代码比较老 ,不好理解,建议 直接都更换了
files:=TDirectory.GetFiles(mypath,'*.dcu',TSearchOption.soAllDirectories) ;
for str1 in files doshowmessage(str1);
两行就解决了;
千影 发表于 2022-6-15 12:17
能肯定是能,就是改动比较大, 想改的少点,直接FilesList1: TStrings 用 FilesList1 替换 Memo1.Lin ...
@千影 终于把你给盼来了,就要这种,简单实干! 我也想共鸣,奈何不入法门!
页:
[1]