这是我的原代码 MoveFile(pchar(FileListBox1.FileName ),pchar(FileListBox1.Directory +ExtractFileName(FileListBox1.FileName ) ));
 cobi!用什么其他函数呢?

解决方案 »

  1.   

    不行的意思是出错还是没有效果?MoveFile(pchar(FileListBox1.FileName ),pchar(FileListBox1.Directory +ExtractFileName(FileListBox1.FileName ) ));
    一、怎么源文件和目标文件一样?
    二、FileListBox1.Directory +ExtractFileName(FileListBox1.FileName )是不是中间缺了“\”?
      

  2.   

    使用 SHFileOperation 函数,具体如下:
    var
      FromFile : String;
      ToFile : String;
      SearchRec : TSearchRec;
      SHFileOpStruct: TSHFileOpStruct;
      FromDir: PChar;
      ToDir: PChar;  FromFile := filename1;
      ToFile := filename2;   GetMem(FromDir, Length(FromFile)+2);
        try
          GetMem(ToDir, Length(ToFile)+2);
          try
            FillChar(FromDir^, Length(FromFile)+2, 0);
            FillChar(ToDir^, Length(ToFile)+2, 0);        StrCopy(FromDir, PChar(FromFile));
            StrCopy(ToDir, PChar(ToFile));        with SHFileOpStruct do
            begin
              Wnd    := Handle;   // Assign the window handle
              wFunc  := FO_COPY;  // Specify a file copy
              pFrom  := FromDir;
              pTo    := ToDir;
              fFlags := 0;
              fAnyOperationsAborted := true;
              hNameMappings := nil;
              lpszProgressTitle := nil;
              if SHFileOperation(SHFileOpStruct) <> 0 then
                RaiseLastWin32Error;
            end;
          finally
            FreeMem(ToDir, Length(ToFile)+2);
          end;
        finally
          FreeMem(FromDir, Length(FromFile)+2);
        end;至于你要做整个目录的拷贝,可以直接把目录名写完全就可以了,不用一个一个文件的拷贝。
      

  3.   

    我的delphi6中没有这个TSHFileOpStruct对象!编译时提示:undeclared identifier:'TSHFileOpStruct'为什么,这样整个目录拷贝!
      

  4.   

    TSHFileOpStruct
    use shellapi,windows
      

  5.   

    用MoveFile的话,目标文件必须不存在,先检查一下。
    MoveFile(pchar(FileListBox1.FileName ),pchar(FileListBox1.Directory +ExtractFileName(FileListBox1.FileName ) ));
    这句的确有问题。
    不过你可以判断MoveFile的返回值,0的话,用ShowMessage(SysErrorMessage(GetLastError()))
    来看看是什么问题。
      

  6.   

    可以在delphi下用dos的命令吗?怎样用!