对文件夹的操作 SHFileOperation()的使用
2011-09-04 20:41
260 查看
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;
}
/////////////////////////////////////
//函数名: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;
}
相关文章推荐
- vc 对文件夹的操作 SHFileOperation()的使用
- 使用SHFileOperation拷贝文件夹
- 1.0使用递归操作遍历文件夹下的所有文件
- linux\mac 日常入门命令行使用——文件以及文件夹操作
- JavaScript中使用ActiveXObject操作本地文件夹的方法
- c#中使用api(shfileoperation)进行文件操作,特别详解了回收站相关参数
- 使用SHFileOperation 复制文件夹
- C#中使用API(SHFileOperation)进行文件操作,特别说明了回收站相关参数
- 使用SHFileOperation删除文件夹报错的问题
- PB利用API-SHFileOperation 文件操作函数 实现多文件及文件夹的删除复制等操作
- C#中使用API(SHFileOperation)进行文件操作,特别说明了回收站相关参数
- NSIS使用SHFileOperation函数移动文件夹
- 使用JavaAPI操作HDFS系统中的文件及文件夹
- JavaScript中使用ActiveXObject操作本地文件夹的方法
- C++_SHFileOperation文件夹操作
- 使用java.nio.file.WatchService监控文件夹里的文件再操作文件出现的“文件不存在或目录不存在”的错误
- PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用
- 关于使用SHFileOperation做文件操作的问题
- 使用Python(comtypes)操作ArcGis(ArcObject)的第一步:安装模块到gen文件夹中