function ExtractFilePath(const FileName: string): string;

解决方案 »

  1.   

    用function ExtractFilePath(const FileName: string): string;例:
    procedure TForm1.Save1Click(Sender: TObject);var
      NewFileName: string;
      Msg: string;
      NewFile: TFileStream;
      OldFile: TFileStream;
    begin
      NewFileName := ExtractFilePath(Application.ExeName) + ExtractFileName(Edit1.Text);
      Msg := Format('Copy %s to %s?', [Edit1.Text, NewFileName]);
      if MessageDlg(Msg, mtConfirmation, mbOKCancel, 0) = mrOK then
      begin
        OldFile := TFileStream.Create(Edit1.Text, fmOpenRead or fmShareDenyWrite);
        try
          NewFile := TFileStream.Create(NewFileName, fmCreate or fmShareDenyRead);      try
            NewFile.CopyFrom(OldFile, OldFile.Size);
          finally
            FreeAndNil(NewFile);
          end;
        finally
          FreeAndNil(OldFile);
        end;
      end;
      

  2.   

    1.本程序:application.exename:string;
    2.其它程序:function ExtractFilePath(const FileName: string): string;
      

  3.   

    我试过了,用ExtractFilePath不行。例如,硬盘上有个程序文件:
    c:\test\p1.exe(它并没有运行),用ExtractFilePath('p1.exe')就能返回
    c:\test吗?不行吧?
      

  4.   

    ExtractFilePath函数只是简单的从FileName参数中取出路径,而不是查找文件所在的目录。
      

  5.   

    可以读注册表,只要这个程序通过按装程序安装而且那个安装程序没有BUG.比如程序A.exeHKEY_LOCAL_MACHINE\Softare\Microsoft\Windows\CurrentVersion
    \App Paths\A.exe,在下面读Path值,这就是A.exe的绝对路径.
      

  6.   

    ExtractFilePath就是可以找到你的文件的路径啊,这一点没错。
    没运行也可以。
      

  7.   

    to Liujc(阿聪):
    大虾所言极是。我也这么认为。因为我用ExtractFilePath('p1.exe')返回的是'',而ExtractFilePath('c:\test\p1.exe'),返回的才是c:\test\,哈哈,既然需事先知道,又何必用它呢?我觉得这不是用一个简单的函数就能搞定的吧?其实这是一个文件查找问题。
    请大家帮忙呀!to BCB_FANS(四大名捕之追杀令) :
    问题是怎样在注册表中快速找到这一项呢?请继续指教。
      

  8.   

    學習:
    有另問題:如果A.exe存在兩個以上的路徑下,我們得到的應該是甚麼呢
      

  9.   

    我不是已经说定很明白了,你要找的程序你总知道它的名城吧???HKEY_LOCAL_MACHINE\Softare\Microsoft\Windows\CurrentVersion
    \App Paths\要找的程序的名城(包括扩展名),在这个键底下读Path这个字符串值,就是路径啊!!!
      

  10.   

    你想要的是一个搜索文件的过程.
    自编一个对硬盘进行Tree遍历的方法去实现,象Windows中的搜索文件一样.
      

  11.   

    BCB_FANS(四大名捕之追杀令):
    谢谢。你的办法较好。to  gxyc76(dd) 
    若用遍历的办法,可能时间很长,(用过windows的查找功能的都有这种体会)