12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #pragma once
- #include "stdafx.h"
- #include "FileAndFolderClass.h"
- /*
- 能产生对话框的标志:
- FOF_SILENT //progress dialog
- FOF_RENAMEONCOLLISION //replace dialog
- FOF_NOCONFIRMATION //confirmation dialog
- FOF_NOCONFIRMMKDIR //asks for your permission to create a new folder
- FOF_NOERRORUI //error message
- FOF_ALLOWUNDO //允许放回回收站,一般这个最好做默认
- FOF_NOCONFIRMATION //不出现确认对话框(当需要覆盖时)
- FOF_SILENT //不显示进度对话框
- FOF_NOERRORUI //No user interface will be displayed if an error occurs.
- FOF_NOCONFIRMMKDIR //如果目的目录不存在,就默认创建,不需确认
- FOF_RENAMEONCOLLISION //如果文件(夹)已存在,自动为其添加序列号修改文件名。此时不会出现确认对话框
- FOF_MULTIDESTFILES //把文件夹里的所有内容复制到FileOp.pTo指定的文件夹里,而不是直接复制一个文件夹
- FOF_SIMPLEPROGRESS //Displays a progress dialog box but does not show the file names
- FOF_CONFIRMMOUSE //Not currently implemented.
- FOF_FILESONLY: //执行通配符,只执行文件;
- FOF_WANTMAPPINGHANDLE: //要求SHFileOperation()函数返回正处于操作状态的实际文件列表,文件列表
- 名柄保存在hNameMappings成员中。SHFILEOPSTRUCT结构还包含一个SHNAMEMAPPING结构的数组,此数组
- 保存由SHELL计算的每个处于操作状态的文件的新旧路径。
- 说明:
- 1.以下封装了4个函数_CopyFile,_DeleteFile,_MoveFile,_ReNameFile
- 2.每个函数都先拷贝了原来的路径,保证了路径是以2个\0\0结尾。(如果不以2个\0\0结尾,往往会出错)
- 3.对于文件或文件夹都适用
- */
- /****************************************************************************
- 复制文件或者文件夹,需要把路径添加2个\0\0
- ****************************************************************************/
- bool _CopyFile(const TCHAR *_pFrom,const TCHAR *_pTo,WORD flags)
- {
- TCHAR pTo[MAX_PATH]={0}; _tcscpy(pTo,_pTo);
- TCHAR pFrom[MAX_PATH]={0}; _tcscpy(pFrom,_pFrom);
- SHFILEOPSTRUCT FileOp={0};
- FileOp.fFlags= flags;
- FileOp.pFrom = pFrom;
- FileOp.pTo = pTo;
- FileOp.wFunc = FO_COPY;
- return SHFileOperation(&FileOp) == 0;
- }
- /****************************************************************************
- 删除文件或者文件夹,需要把路径添加2个\0\0
- ****************************************************************************/
- bool _DeleteFile(const TCHAR* _pFrom,WORD flags)
- {
- TCHAR pFrom[MAX_PATH]={0}; _tcscpy(pFrom,_pFrom);
- SHFILEOPSTRUCT FileOp={0};
- FileOp.pFrom = pFrom;
- FileOp.pTo = NULL; //一定要是NULL
- FileOp.fFlags= flags;
- FileOp.wFunc = FO_DELETE; //删除操作
- return SHFileOperation(&FileOp) == 0;
- }
- /****************************************************************************
- 移动文件或者文件夹,需要把路径添加2个\0\0
- ****************************************************************************/
- bool _MoveFile(const TCHAR *_pFrom,const TCHAR *_pTo,WORD flags)
- {
- TCHAR pTo[MAX_PATH]={0}; _tcscpy(pTo,_pTo);
- TCHAR pFrom[MAX_PATH]={0}; _tcscpy(pFrom,_pFrom);
- SHFILEOPSTRUCT FileOp={0};
- FileOp.fFlags= flags;
- FileOp.pFrom = pFrom;
- FileOp.pTo = pTo;
- FileOp.wFunc = FO_MOVE;
- return SHFileOperation(&FileOp) == 0;
- }
- /****************************************************************************
- 重命名文件或者文件夹
- 可以的话用 rename(buf,TempFilePath) (文件和文件夹都可以) because不需要把路径添加2个\0\0
- ****************************************************************************/
- bool _ReNameFile(const TCHAR *_pFrom,const TCHAR *_pTo,WORD flags)
- {
- TCHAR pTo[MAX_PATH]={0}; _tcscpy(pTo,_pTo);
- TCHAR pFrom[MAX_PATH]={0}; _tcscpy(pFrom,_pFrom);
- SHFILEOPSTRUCT FileOp={0};
- FileOp.fFlags = flags;
- FileOp.pFrom = pFrom;
- FileOp.pTo = pTo;
- FileOp.wFunc = FO_RENAME;
- return SHFileOperation(&FileOp) == 0;
- }
|