Registriert seit: 6. Apr 2005
10.109 Beiträge
|
Re: Prüfen ob ein verzeichnis die gewünschte erweiterungen h
15. Okt 2006, 17:58
Hallo Michael,
schau dir das mal an:
Delphi-Quellcode:
procedure GetSubdirsContaining(const dir: TFileName; sExt, sDir: TStrings; recurse: Boolean = False);
var
i: Integer;
s: TStrings;
sr: TSearchRec;
dirName: TFileName;
begin
s := TStringList.Create;
dirName := IncludeTrailingPathDelimiter(dir);
try
if FindFirst(dirName + '*.*', faDirectory, sr) = 0 then
begin
repeat
if AnsiStartsText(sr.Name, '..') then
Continue else
if sr.Attr and faDirectory = faDirectory then
begin
s.Add(dirName + sr.Name);
Continue;
end else
if sExt.IndexOf(ExtractFileExt(sr.Name)) < 0 then
Continue;
if sDir.IndexOf(dirName) < 0 then
sDir.Add(dirName);
until FindNext(sr) <> 0;
FindClose(sr);
end;
for i := 0 to Pred(s.Count) do
GetSubDirsContaining(s[i], sExt, sDir, True);
finally
s.Free;
end;
end;
procedure TDemoForm.GatherButtonClick(Sender: TObject);
var
sExt: TStrings;
begin
sExt := TStringList.Create;
sExt.CommaText := '.mp3,.wav,.m4a';
try
with DirBox do
begin
Items.BeginUpdate;
Items.Clear;
GetSubDirsContaining('c:\Media\', sExt, Items, True);
Items.EndUpdate;
end;
finally
sExt.Free;
end;
end;
Grüße
|
|
Zitat
|