使用函数:
System.IOUtils.TDirectory.IsEmpty
class function IsEmpty(const Path: string): Boolean; static;
说明:参数为给定目录,返回布尔值
异常处理:指定目录为空或无效
代码:
var sDir: string; procedure TForm1.Button1Click(Sender: TObject); begin if not SelectDirectory('', 'H:\', sDir) then Exit; end; procedure TForm1.Button_CheckClick(Sender: TObject); begin try if TDirectory.IsEmpty(sDir) then begin ShowMessage('此目录为空。'); Exit; end; ShowMessage('此目录不为空。'); except on e: Exception do begin MessageDlg(e.ClassName + ' : ' + e.Message, mtError, [mbok], 0); Exit; end; end; end;