File Operation using SHFileOperation
SHFILEOPSTRUCT
Original link: http://winapi.freetechsecrets.com/win32/WIN32SHFILEOPSTRUCT.htm
Reference linke: SHFileOperation方法拷贝文件
Contains information that the SHFileOperation function uses to perform file operations.
typedef struct _SHFILEOPSTRUCT { // shfos
HWND hwnd;
UINT wFunc;
LPCSTR pFrom;
LPCSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCSTR lpszProgressTitle;
} SHFILEOPSTRUCT, FAR *LPSHFILEOPSTRUCT;
Members
hwnd
Handle of the dialog box to use to display information about the status of the operation.
wFunc
Operation to perform. This member can be one of the following values:
|
FO_COPY |
Copies the files specified by pFrom to the location specified by pTo. |
|
FO_DELETE |
Deletes the files specified by pFrom (pTo is ignored). |
|
FO_MOVE |
Moves the files specified by pFrom to the location specified by pTo. |
|
FO_RENAME |
Renames the files specified by pFrom. |
pFrom
Pointer to a buffer that specifies one or more source file names. Multiple names must be null-separated. The list of names must be double null-terminated.
pTo
Pointer to a buffer that contains the name of the destination file or directory. The buffer can contain mutiple destination file names if the fFlags member specifies FOF_MULTIDESTFILES. Multiple names must be null-separated. The list of names must be double null-terminated.
fFlags
Flags that control the file operation. This member can be a combination of the following values:
|
FOF_ALLOWUNDO |
Preserves undo information, if possible. |
|
FOF_CONFIRMMOUSE |
Not implemented. |
|
FOF_FILESONLY |
Performs the operation only on files if a wildcard filename (*.*) is specified. |
|
FOF_MULTIDESTFILES |
Indicates that the pTo member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited. |
|
FOF_NOCONFIRMATION |
Responds with "yes to all" for any dialog box that is displayed. |
|
FOF_NOCONFIRMMKDIR |
Does not confirm the creation of a new directory if the operation requires one to be created. |
|
FOF_RENAMEONCOLLISION |
Gives the file being operated on a new name (such as "Copy #1 of...") in a move, copy, or rename operation if a file of the target name already exists. |
|
FOF_SILENT |
Does not display a progress dialog box. |
|
FOF_SIMPLEPROGRESS |
Displays a progress dialog box, but does not show the filenames. |
|
FOF_WANTMAPPINGHANDLE |
Fills in the hNameMappings member. The handle must be freed by using the SHFreeNameMappings function. |
fAnyOperationsAborted
Value that receives TRUE if the user aborted any file operations before they were completed or FALSE otherwise.
hNameMappings
Handle of a filename mapping object that contains an array of SHNAMEMAPPING structures. Each structure contains the old and new path names for each file that was moved, copied, or renamed. This member is used only if fFlags includes FOF_WANTMAPPINGHANDLE.
lpszProgressTitle
Pointer to a string to use as the title for a progress dialog box. This member is used only if fFlags includes FOF_SIMPLEPROGRESS.
Remarks
If pFrom or pTo are unqualified names, the current directories are taken from the global current drive and directory settings as managed by the GetCurrentDirectory and SetCurrentDirectory functions.
See Also
GetCurrentDirectory, SetCurrentDirectory, SHFileOperation, SHFreeNameMappings, SHNAMEMAPPING
__________________________________________________________________________________________
Example:
Copy a file to a specific path and rename it.
TCHAR* chFrom =_T("C:\\TEST\\A\\gg.txt");
TCHAR* chTo=_T("C:\\TEST\\B\\gg.txt");
TCHAR* chNewName=_T("C:\\TEST\\B\\new.txt");
SHFILEOPSTRUCT shFileOp;
ZeroMemory(&shFileOp, sizeof(SHFILEOPSTRUCT));
shFileOp.wFunc=FO_COPY;
shFileOp.pFrom=chFrom+'\0';
shFileOp.pTo=chTo+'\0';
shFileOp.fFlags=FOF_NOCONFIRMATION|FOF_SILENT;
DWORD dwCopyValue= SHFileOperation (&shFileOp);
//char buffer[32];
//ltoa((long)dwCopyValue, buffer, 10);
char procID[];
sprintf(procID, "%d",dwCopyValue);
if(dwCopyValue!=)
{
CString strMessage;
strMessage.Format(_T("The copy operation failed.\n The error code of SHFileOperation is %d"), dwCopyValue);
MessageBox(NULL, strMessage , _T("Alert"), MB_OK);
return dwCopyValue;
} shFileOp.wFunc=FO_RENAME+'\0';
shFileOp.pFrom=chTo+'\0';
shFileOp.pTo=chNewName+'\0'; DWORD dwRenameValue= SHFileOperation (&shFileOp);
if(dwRenameValue!=)
{
MessageBox(NULL, _T("The rename operation failed, error code is ! "+dwRenameValue), _T("Alert"), MB_OK);
return dwRenameValue;
}
Possible error code:
Go to this link System Error Codes to see what each code means.
1) SHFileOperation returns 124
124 means:
ERROR_INVALID_LEVEL
124 (0x7C)
The system call level is not correct.
DE_INVALIDFILES
0x7C
The path in the source or destination or both was invalid.
Make sure the source or destination path is valid.
2) SHFileOperation returns 2
ERROR_FILE_NOT_FOUND
2 (0x2)
The system cannot find the file specified.
Make sure the file being operated exists.
File Operation using SHFileOperation的更多相关文章
- mysql数据库报错:InnoDB: Operating system error number 13 in a file operation
环境:centos6.5 x86_64 启动mysql发现日志报错(日志路径可以查看/etc/my.cnf的配置) 160722 10:34:08 [Note] Found 42570716 of 4 ...
- InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法
InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法 140628 8:10:48 [Note] Plugi ...
- Python:文件操作技巧(File operation)(转)
Python:文件操作技巧(File operation) 读写文件 # ! /usr/bin/python # -*- coding: utf8 -*- spath = " D:/dow ...
- Adobe ZXPInstaller 报错 Installation failed because of a file operation error.
1. Drag a ZXP file or click here to select a file. 拖放一个 zxp 文件或点击打开选择一个 zxp 文件来安装: 2. Installation f ...
- Python & file operation mode
Python & file operation mode create/read/write/append mode https://docs.python.org/3/library/fun ...
- Mac OS X系统下,svn: Can't remove file Operation not permitted.解决方案
当你的svn出现类似以下错误时,提示Operation not permitted之类的问题,说明项目下 .svn文件夹内的文件权限有问题. 一般是由于windows和mac操作系统同时操作同个svn ...
- PythonStudy——文件操作 File operation
# 文件:就是硬盘的一块存储空间 # 1.使用文件的三步骤: # 打开文件- 得到文件对象:找到数据存放在硬盘的位置,让操作系统持有该空间,具有操作权# 硬盘空间 被 操作系统持有# 文件对象f 被 ...
- file operation note
从HLE回来,大家拍了2499张照片,分放在N个文件夹下,下面的python将下层目录中文件移动到上层 import os,shutil dst=os.getcwd()+os.sep for path ...
- python file operation
file.open(name[,mode[,buffering]]) 模式的类型有: r 默认只读 w 以写方式打开,如果文件不存在则会先创建,如果文件存在则先把文件内容清空(truncate ...
随机推荐
- iOS开发-分页栏和选取器的使用
一.分页栏 创建一个新的项目,Subclass of的值选中UIViewController,然后在storyboard中删除根视图,在右下方拖出一个Tab Bar Controller 新增分页,只 ...
- Innodb 锁 (简单笔记)
看过很多innodb锁的文章,已经明白的就不写了,简单做个笔记 Innodb 锁的兼容性: 1.意向锁和意向锁之间都是兼容的 2.X(排他锁)与任何锁都是不兼容的 3.排他意向锁 IX 于S锁是不 ...
- 使用Knoctout.分页
要点:点击标签翻页部分时,pageValue自动加1. 1.api中的方法 public ArticleListModel Get(int page,string _class) { var list ...
- 2015北京网络赛 H题 Fractal 找规律
Fractal Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingo ...
- eclipse代码提示框背景色改动
因为个人习惯,喜欢把eclipse的文本编辑框背景调成全黑色,可是代码提示框的默认背景色也是黑色.所以两者就冲突了.导致看不到代码提示框的内容. 后来发现代码提示框的背景色能够改动.改动内容例如以下: ...
- linux crt
1.仿真 终端选linux ANSI颜色[有颜色了] 使用颜色方案[颜色加深了] 2.外观 选传统的 ,utf-8 就不会乱码了
- javascript笔记02:严格模式的特定要求
1.严格模式变量必须声明,不然会报错: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- ListView滑动不爽,滚动一页得滑几次?该用分页列表啦!
ListView等滚动位置经常不符合用户期望: 很多时候都是看完一页想滑到下一页,但滑动一次距离往往不是不够就是超过,很难控制. PagedListView工程中提供了PageScroller来解决这 ...
- 你真的会用UIButton吗? UIButton详细介绍
本节知识点: 什么是UIButton UIButton的状态 UIButton的属性设置 UIButton基本使用步骤 UIButton的代码创建与常用属性设置 重写按钮的某个状态属性的 setter ...
- 关于automatic_Panoramic_Image_Stitching_using_Invariant_features 的阅读笔记
并没有都读完,不过感觉还是有必要做一个笔记的,毕竟这只是随笔不是文章,所以可以有多少写多少,也算是工作总结了,最重要的是这个好在可以,完成所有有意义文档的检索,比起自己的word来说高级很多~~~. ...