whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

79 Visitors Online


 
...check, if a directory is empty?
Autor: RaverJK
[ Print tip ]  

Tip Rating (34):  
     


// Diese Funktion gibt true zurück, falls Directory ein leeres Verzeichnis ist.
// This function returns true if Directory is an empty directory.

function DirectoryIsEmpty(Directory: string): Boolean;
var
  
SR: TSearchRec;
  i: Integer;
begin
  
Result := False;
  FindFirst(IncludeTrailingPathDelimiter(Directory) + '*', faAnyFile, SR);
  for i := 1 to do
    if 
(SR.Name = '.') or (SR.Name = '..') then
      
Result := FindNext(SR) <> 0;
  FindClose(SR);
end;


// Beispiel:
// Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
DirectoryIsEmpty('C:\test') then
    
Label1.Caption := 'empty'
  else
    
Label1.Caption := 'not empty';
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners