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] = '\0';

  NewPathFrm[nLengthFrm+1] = '\0';

  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] = '\0';

  NewPathFrm[nLengthFrm+1] = '\0';

  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] = '\0';

  NewPath[nLength+1] = '\0';

  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] = '\0';

  NewPathFrm[nLengthFrm+1] = '\0';

  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;

  }

最新文章

  1. bzoj4559: [JLoi2016]成绩比较
  2. JS操作cookies方法
  3. Ext5实现树形下拉框ComboBoxTree
  4. ASCII编码对照表
  5. base64/62 加解密的实现。
  6. WinForm 窗体应用程序 (初步)之二
  7. CSS 高级技巧汇总
  8. node.js和express.js安装和使用步骤 [windows]
  9. 20145208 实验五 Java网络编程
  10. Python读写文件乱码问题
  11. 十进制和n进制的转换(10进制转换为36进制)
  12. 前端技术——WebFont与Sprite
  13. CTF 字符统计1
  14. Linux Centos安装及卸载Apache
  15. Windows下搭建kafka运行环境
  16. [转帖]SPU、SKU、ID,它们都是什么意思,三者又有什么区别和联系呢?
  17. Nagios 使用 NSClient++ 监控Windows Server
  18. marathon 测试
  19. [TJOI2011]构造矩阵
  20. 单机部署PXC

热门文章

  1. Linux中useradd的用法
  2. Linux系统安装-C7
  3. sonarqube 8.9版本配置收邮件提醒
  4. Java Set HashSet
  5. 关于windows11的0x800f0950语言包安装失败
  6. Nginx:Nginx的安装
  7. linux学习之路第六天(文件目录类第二部分)
  8. netcore3.1 + vue (前后端分离)生成PDF(多pdf合并)返回前端打印
  9. 『心善渊』Selenium3.0基础 — 28、unittest中测试套件的使用
  10. java基础---设计模式(2)