现在的位置: 首页 > 综合 > 正文

C++拷贝文件

2013年10月08日 ⁄ 综合 ⁄ 共 1328字 ⁄ 字号 评论关闭

API函数拷贝文件夹  
  void     OnFilecopy()  
  {  
            int   nOk;  
            char     strSrc[]="c://dos/0c://pwin98//command/0";  
            //可以改变源路径  
            char     strDst[]="c://temp/0";  
            //设置目的路径  
            char     strTitle[]="File   copying";  
            //进度题头  
            SHFILEOPSTRUCT   FileOp;  
            FileOp.hwnd=m_hWnd;  
            FileOp.wFunc=FO_COPY;  
            //执行文件拷贝  
            FileOp.pFrom=strSrc;  
            FileOp.pTo=strDst;  
            FileOp.fFlags=FOF_ALLOWUNDO;  
            FileOp.hNameMappings=NULL;  
            FileOp.lpszProgressTitle=strTitle;  
   
                  nOk=SHFileOperation(&FileOp);  
                  if(nOk)  
                          TRACE("There   is   an   error:   %d/n",nOk);  
                  else  
                        TRACE("SHFileOperation   finished   successfully/n");  
   
                    if(FileOp.fAnyOperationsAborted)  

/////////////////////////////////////////////////////////////////

BOOL   CopyFile(  
      LPCTSTR   lpExistingFileName,   //   name   of   an   existing   file  
      LPCTSTR   lpNewFileName,             //   name   of   new   file  
      BOOL   bFailIfExists                     //   operation   if   file   exists  
  );

copyfile

  
  VB声明
  Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
  说明
  复制文件。与vb的filecopy命令相似
  返回值
  Long,非零表示成功,零表示失败。会设置GetLastError
  参数表
  参数 类型及说明
  lpExistingFileName String,源文件名
  lpNewFileName String,目标文件名
  bFailIfExists Long,如果设为TRUE(非零),那么一旦目标文件已经存在,则函数调用会失败。否则目标文件被改写

抱歉!评论已关闭.