zoukankan      html  css  js  c++  java
  • MFC对文件文件夹转移、删除、重命名、复制【转】

    HFileOperation()函数主要对文件夹有四种操作:复制,删除,移动,重命名。

    写了四个函数。可以很好的对文件夹进行操作。

     

    //函数名:MoveFolder

      //参数:lpszFromPath 源文件夹路径 。lpszToPath 目的文件夹路径

      //作用:移动原文件夹及其中文件都指定的路径下

      //

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

      BOOL MoveFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)

      {

      int nLengthFrm = strlen(lpszFromPath);

      char *NewPathFrm = new char[nLengthFrm+2];

      strcpy(NewPathFrm,lpszFromPath);

      NewPathFrm[nLengthFrm] = '';

      NewPathFrm[nLengthFrm+1] = '';

      SHFILEOPSTRUCT FileOp;

      ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

      FileOp.fFlags = FOF_NOCONFIRMATION ;

      FileOp.hNameMappings = NULL;

      FileOp.hwnd = NULL;

      FileOp.lpszProgressTitle = NULL;

      FileOp.pFrom = NewPathFrm;

      FileOp.pTo = lpszToPath;

      FileOp.wFunc = FO_MOVE;

      return SHFileOperation(&FileOp) == 0;

      }

     

     

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

      //ReNameFolder

      //参数:lpszFromPath 源文件夹路径 。lpszToPath 目的文件夹路径

      //作用:修改原文件夹的名字。

      //

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

      BOOL ReNameFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)

      {

      int nLengthFrm = strlen(lpszFromPath);

      char *NewPathFrm = new char[nLengthFrm+2];

      strcpy(NewPathFrm,lpszFromPath);

      NewPathFrm[nLengthFrm] = '';

      NewPathFrm[nLengthFrm+1] = '';

      SHFILEOPSTRUCT FileOp;

      ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

      FileOp.fFlags = FOF_NOCONFIRMATION ;

      FileOp.hNameMappings = NULL;

      FileOp.hwnd = NULL;

      FileOp.lpszProgressTitle = NULL;

      FileOp.pFrom = NewPathFrm;

      FileOp.pTo = lpszToPath;

      FileOp.wFunc = FO_RENAME;

      return SHFileOperation(&FileOp) == 0;

      }


     

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

      //函数名:DeleteFolder

      //输入参数:LpszPath 要删除的路径指针

      //作用:删除指定文件夹以及里面的文件

      //

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

      BOOL DeleteFolder(LPCTSTR lpszPath)

      {

      int nLength = strlen(lpszPath);

      char *NewPath = new char[nLength+2];

      strcpy(NewPath,lpszPath);

      NewPath[nLength] = '';

      NewPath[nLength+1] = '';

      SHFILEOPSTRUCT FileOp;

      ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

      FileOp.fFlags = FOF_NOCONFIRMATION;

      FileOp.hNameMappings = NULL;

      FileOp.hwnd = NULL;

      FileOp.lpszProgressTitle = NULL;

      FileOp.pFrom = NewPath;

      FileOp.pTo = NULL;

      FileOp.wFunc = FO_DELETE;

      return SHFileOperation(&FileOp) == 0;

      }

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

      //函数名:CopyFolder

      //参数:lpszFromPath 源文件夹的路径 。 lpszToPath 目的文件夹的路径

      //作用:拷贝文件夹及其文件夹中的所有内容

      //

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

      BOOL CopyFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)

      {

      int nLengthFrm = strlen(lpszFromPath);

      char *NewPathFrm = new char[nLengthFrm+2];

      strcpy(NewPathFrm,lpszFromPath);

      NewPathFrm[nLengthFrm] = '';

      NewPathFrm[nLengthFrm+1] = '';

      SHFILEOPSTRUCT FileOp;

      ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));

      FileOp.fFlags = FOF_NOCONFIRMATION ;

      FileOp.hNameMappings = NULL;

      FileOp.hwnd = NULL;

      FileOp.lpszProgressTitle = NULL;

      FileOp.pFrom = NewPathFrm;

      FileOp.pTo = lpszToPath;

      FileOp.wFunc = FO_COPY;

      return SHFileOperation(&FileOp) == 0;

      }

  • 相关阅读:
    Android学习(九) SharedPreferences
    Android学习(八) 打开Activity
    Android学习(七) Android实现计算器
    Android学习(六) 文本框边框
    Android学习(五) 圆角实现(转)
    Android学习(四) Layout五大布局
    Android学习(三) 自动完成的使用
    SQL Server中的三种物理连接操作
    ASP.NET实现大文件下载
    ASP.NET上传大文件的问题
  • 原文地址:https://www.cnblogs.com/ericdm/p/9049295.html
Copyright © 2011-2022 走看看