各位大侠:
    小弟想在c:\winnt放置一个文件a.txt,如何在程序运行时检测并判断是否存在此文件,如果存在则运行程序,否则产生一警告信息并退出程序,请给出代码,谢谢!

解决方案 »

  1.   

    windir:=‘c:\winnt\a.txt
    if  FileExists(WinDir) then ShellExecute(handle, 'open', windir, nil, nil, SW_SHOWNORMAL)
    else 
    begin
      showmessage('无此程序’);
      Application.Terminate;
    end;
      

  2.   

    http://www.resbbs.com/dispbbs.asp?boardid=9&id=176
      

  3.   

    program Project1;uses
      Forms,windows,dialogs,SysUtils,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}
      var
      WinDir: array[0..MAX_PATH] of char;   // holds the Windows directory
    begin
      Application.Initialize;
      {retrieve the Windows directory...}
      GetWindowsDirectory(WinDir, MAX_PATH);
      if not fileexists(StrPas(WinDir)+'\'+'a.txt') then
      begin
        showmessage('存在文件推出程序');
        application.Terminate;
      end;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.