Mega Code Archive

 
Categories / Delphi / Files
 

Is the directory empty (the simpliest way !)

Title: Is the directory empty ? (the simpliest way !) Question: How to determine if a directory is empty Answer: The following function is a simple way to determine if a directory is empty. The trick is to look for other files and directories than the two first found DOS directories '.' and '..'. function IsDirEmpty (const ADirPath :string) :boolean; var F :TSearchRec; begin result := (FindFirst(ADirPath+'\*.*',faAnyFile,F) = 0) and (FindNext(F) = 0) and (FindNext(F) 0); FindClose(F); end;