在DEPHI中根据已知路径打开目录应该怎么写?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    const
        SELDIRHELP = 1000;
    var
      dir: String;
    begin
      dir := 'C:';
      if SelectDirectory(dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
        Button1.Caption := dir;
    end;
      

  2.   

    该问题业已解决,与大家共享!
    var
      Form1: TForm1;
      FromDir,ToDir: pchar;
    implementation{$R *.dfm}
    procedure FileCopy(From, Dest: string);
    var  T: TSHFileOpStruct;begin
      GetMem(FromDir,Length(Fromdir)+2);
      try
        GetMem(ToDir,Length(Dest)+2);
        try
          FillChar(FromDir^,Length(From)+2,0);
          FillChar(ToDir^,Length(Dest)+2,0);      StrCopy(FromDir,PChar(From));
          StrCopy(ToDir,PChar(Dest));
          with T do
          begin
            Wnd    :=0;
            wFunc  :=FO_COPY;
            pFrom  :=FromDir;
            pTo    :=ToDir;
            fflags:=FOF_FILESONLY;
            //fFlags :=FOF_RENAMEONCOLLISION ;
            //FOF_NOCONFIRMATION; //or FOF_RENAMEONCOLLISION or (FOF_FILESONLY);
            fAnyOperationsAborted:=False;
            hNameMappings:=nil;
            lpszProgressTitle:=nil;
            if SHFileOperation(T)<>0 then
              raise Exception.Create('拷貝文件失敗!');
          end;
        finally
          FreeMem(ToDir,Length(Dest)+2);
        end;
      finally
        FreeMem(FromDir,Length(From)+2);
      end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    const
        SELDIRHELP = 2000;
    var
      dir: String;
    begin
      dir := 'q:';
      if SelectDirectory(dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
        fromdir:=pchar(dir+'\'+'*.*');
        ToDir:='c:\test\';
        FileCopy(pchar(fromdir),pchar(todir));
    end;end.
      

  3.   

    可以这样写:
    uses shellapi;//shellexecute函数在此单元shellexecute(handle,'explorer','C:\windows',nil,nil,...);// 不好意思,参数个数忘了,后面的都设为nil。
      

  4.   

    給你一個例子:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    winexec('c:\winnt\notepad.exe',sw_normal);
    end;
    樓上的也可以!
      

  5.   

    winexec('c:\windows\EXPLORER.EXE c:\windows',sw_normal);