我有一组文件:
001.txt
001a.txt
002.txt
002a.txt
...
我正在尝试使用以下代码排除以a
结尾的项目,例如001a.txt
PROCEDURE TForm1.FindFiles(StartDir, FileMask: STRING);
VAR
sr: TSearchRec;
IsFound: Boolean;
BEGIN
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, sr) = 0;
WHILE IsFound DO
BEGIN
if sr.Name <> '*a.*' then
gFiles.add(StartDir + sr.Name);
IsFound := FindNext(sr) = 0;
END;
FindClose(sr);
END;
传递给此过程的 FileMask
是 '*.*'
以包含所有文件。
但是上面返回所有文件。
所以我的问题是如何从搜索中排除这些文件?
最佳答案
Delphi 为此提供了 System.Masks
单元。这里合适的函数是MatchesMask :
if MatchesMask(sr.Name, '*a.*') then
关于delphi - 我可以使用通配符来比较字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62170689/