在innosetup里面有什么命令可以实现这个功能。我只看到copy和copyfile 这2个命令只能copy文件,不能copy整个文件夹

解决方案 »

  1.   

    将c:\abc复制到c:\temp的代码如下:uses ShellApi;
    procedure TForm1.Button3Click(Sender: TObject);
    var
      OpStruc: TSHFileOpStruct;
      frombuf, tobuf: Array [0..128] of Char;
    Begin
      FillChar( frombuf, Sizeof(frombuf), 0 );
      FillChar( tobuf, Sizeof(tobuf), 0 );
      StrPCopy( frombuf, 'c:\abc\*.*' );
      StrPCopy( tobuf, 'c:\temp' );
      With OpStruc DO Begin
        wFunc:= FO_COPY;
        pFrom:= @frombuf;
        pTo:=@tobuf;
        fFlags:= FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR;
        fAnyOperationsAborted:= False;
        hNameMappings:= Nil;
        lpszProgressTitle:= Nil;
      end;
      ShFileOperation( OpStruc );
    end;
      

  2.   

    确实没找到
    可以试试
    function FindFirst(const FileName: String; var FindRec: TFindRec): Boolean; 
    function FindNext(var FindRec: TFindRec): Boolean; 
    procedure FindClose(var FindRec: TFindRec); 
    查找文件然后一个个的复制过去,如果遇到文件夹就递归调用。
      

  3.   

    楼上的老哥几位,楼长问的是在inno中,不是在delphi里
      

  4.   


    我说的就是Inno Setup。
      

  5.   

    function CopyFolder(const SourceFolderPath: String; DestinyFolderPath: String): Boolean;
    var
        strSrc: String;
        strDst: String;
        FindRec: TFindRec;
        FilesFound: Integer;begin
        //get first file
        strSrc := SourceFolderPath + '\*.*';
        //strSrc := FindFirst(strSrc,FindRec);
         if (strSrc <> '.') and (strSrc <> '..') then
            begin            // get the destiny and source paths
                strDst := DestinyFolderPath + '' + strSrc;
                //strSrc := strKfxTempPath + '' + strSrc;
        if FindFirst(ExpandConstant('{strSrc}\*'), FindRec) then begin
             try
          repeat
            if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
              FilesFound := FilesFound + 1;
          until not FindNext(FindRec);       finally
          FindClose(FindRec);
           end;
            end;
      MsgBox(IntToStr(FilesFound) + ' files found in the System directory.',
        mbInformation, MB_OK);
    end;
      
                      if not FileCopy(strSrc, strDst, false) then
                begin
                    //erro on copy
                    MsgBox('Erro on copy ' + strSrc + ' to ' + strDst, mbError, MB_OK);
                    Result := false;
                    exit;
                end;
          
            //get next file
            //strSrc := FindNext;    //return OK
        Result := true;
    end;
      

  6.   

    [Files]
    Source:"*"; DestDir: "{app}"
      

  7.   

    我要在code段实现,不要用files
      

  8.   


    function CopyDir(sDirName:String;sToDirName:String):Boolean;
    var
      t,tfile:String;
      FindRec: TFindRec;
    begin
      result:=true;
      if FindFirst(sDirName+'\*.*', FindRec) then 
      begin
        if not DirExists(sToDirName) then
            ForceDirectories(sToDirName);
        try
          repeat
            tfile:=FindRec.name;
            if (tfile<>'.') and (tfile<>'..') then 
            begin
              if FindRec.Attributes = FILE_ATTRIBUTE_DIRECTORY  then
              begin
                  t:=sToDirName+'\'+tfile;
                  if not DirExists(t)  then
                    ForceDirectories(t);
                  if  sDirName[Length(sDirName)]<>'\'   then
                     CopyDir(sDirName+'\'+tfile,t)
                  else
                     CopyDir(sDirName+tfile,sToDirName+tfile);
              end
              else
              begin
                t:=sToDirName+'\'+tFile;
                FileCopy(sDirName+'\'+tfile,t,false);
              end
            end
          until not FindNext(FindRec);
        finally
          FindClose(FindRec);
        end;
      end
      else
        result:=false;
    end;
    调用
    CopyDir('D:\检验数据备份','C:\TestCopy');
      

  9.   


    function CopyDir(sDirName:String;sToDirName:String):Boolean;
    var
      t,tfile:String;
      FindRec: TFindRec;
    begin
      result:=true;
      if FindFirst(sDirName+'\*.*', FindRec) then 
      begin
        if not DirExists(sToDirName) then
            ForceDirectories(sToDirName);
        try
          repeat
            tfile:=FindRec.name;
            if (tfile<>'.') and (tfile<>'..') then 
            begin
              if FindRec.Attributes = FILE_ATTRIBUTE_DIRECTORY  then
              begin
                  t:=sToDirName+'\'+tfile;
                  if not DirExists(t)  then
                    ForceDirectories(t);
                  if  sDirName[Length(sDirName)]<>'\'   then
                     CopyDir(sDirName+'\'+tfile,t)
                  else
                     CopyDir(sDirName+tfile,sToDirName+tfile);
              end
              else
              begin
                t:=sToDirName+'\'+tFile;
                FileCopy(sDirName+'\'+tfile,t,false);
              end
            end
          until not FindNext(FindRec);
        finally
          FindClose(FindRec);
        end;
      end
      else
        result:=false;
    end;
    调用:
    CopyDir('D:\检验数据备份','c:\testcopy');
      

  10.   

    请问文件拷贝 把里面的Dir改为File后, 就可以了吗?
      

  11.   

    findfirst 这个函数是找文件不是找文件夹
      

  12.   

    DELPHI编程能实现吗?????
      

  13.   

    DELPHI不适合在innosetup里面做。有些关键字不适合