if fileexists('c:\123.txt') then showmessage('ok')
問題一: 請用Excel的錄制宏.錄制你想要的動作,再去看它為你寫好的VB代碼.回到Delphi里把 那些VB 代碼翻成Pascal就ok了!問題二: 看以下源碼: Function isExists(adir : string;Ex:string):boolean; var sr: TSearchRec; FileAttrs: Integer; begin Result := False ; FileAttrs := faAnyFile; if aDir[Length(adir)]<>'\' then aDir := aDir + '\'; if SysUtils.FindFirst(aDir+Ex, FileAttrs, sr) = 0 then begin Result := True ; SysUtils.FindClose(sr); end; end;procedure TForm1.Button1Click(Sender: TObject); begin if isExists('f:\','*.JPg') then caption := 'OK'; end;
那些VB 代碼翻成Pascal就ok了!問題二: 看以下源碼:
Function isExists(adir : string;Ex:string):boolean;
var
sr: TSearchRec;
FileAttrs: Integer;
begin
Result := False ;
FileAttrs := faAnyFile;
if aDir[Length(adir)]<>'\' then
aDir := aDir + '\';
if SysUtils.FindFirst(aDir+Ex, FileAttrs, sr) = 0 then
begin
Result := True ;
SysUtils.FindClose(sr);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if isExists('f:\','*.JPg') then
caption := 'OK';
end;