设为首页 加入收藏

TOP

vc对文件夹的操作SHFileOperation()的使用
2014-10-31 23:45:07 来源: 作者: 【 】 浏览:44
Tags:文件夹 操作 SHFileOperation 使用

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


  挤时间对这个函数进行了利用了一下。写了四个函数。可以很好的对文件夹进行操作。


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


  //函数名: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;


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇VC中用函数读写ini文件的方法 下一篇VC实现托盘程序

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: