在D的某个目录下有一个DELPHI编写的程序,如何用函数得到我要的目录?如d:\a\delphipragam,我编写程序都在此目录下,我想得到这个目录,将INI文件和一些日志文件放在这里。在线等。

解决方案 »

  1.   

    Edit1.Text := ExtractFileDir(Application.ExeName);
      

  2.   

    Edit1.Text := ExtractFileDir(Application.ExeName); 取得的结果路径中不带'\',而
    Edit1.Text := ExtractFilePath(Application.ExeName); 带
      

  3.   

    ExtractFileDir(Application.ExeName);//不带\  c:\aabcExtractFilePath(Application.ExeName);//带\   c:\aabc\
     
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      hand : Cardinal;
      fd : _WIN32_FIND_DATAA;
      filename : PAnsiChar;
      item : TListItem;
    begin
    //分配内存并取得当前目录
      ListView1.Clear;
      filename := StrAlloc(256);
      GetCurrentDirectory(256,filename);  StrCat(filename,'\*');
      hand := Windows.FindFirstFile(filename,fd);
      item:=ListView1.Items.Add;//将找到的文件名加入listview
      item.Caption:=fd.cFileName;
      while(GetLastError() <> ERROR_NO_MORE_FILES) do//继续查找直到结束
      begin
        Windows.FindNextFile(hand,fd);
        item:=ListView1.Items.Add;
        item.Caption:=fd.cFileName;  end;
      Windows.FindClose(hand);//关闭查找句柄
      StrDispose(filename);
    end;
    //试试这个
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      dir:string;
    begin
      dir:=ExtractFileDir(Application.Exename);
      showmessage(dir);
    end;
      

  6.   

    用下面这个方法好点,如果你的程序是服务程序或者是被别的程序调用的话,直接ExtractFilePath是不行的 :)
    var strAppDir,ExePath:String;
    //获取目录名
      SetLength(strAppDir,256);
      SetLength(strAppDir, GetModuleFileName(HInstance, PChar(strAppDir), 256));
      ExePath:=ExtractFilePath(strAppDir);
      if ExePath[Length(ExePath)]<>'\' then ExePath:=ExePath+'\';
      

  7.   

    Application的ExeName属性可以获得程序的绝对文件名,进一步获得程序的路经名
          Path:=ExtractFilePath (Application.ExeName);
      

  8.   

    同意。
    var strAppDir,ExePath:String;
    //获取目录名
      SetLength(strAppDir,256);
      SetLength(strAppDir, GetModuleFileName(HInstance, PChar(strAppDir), 256));
      ExePath:=ExtractFilePath(strAppDir);
      if ExePath[Length(ExePath)]<>'\' then ExePath:=ExePath+'\';