首页 技术 正文
技术 2022年11月23日
0 收藏 859 点赞 2,452 浏览 4322 个字

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

GetCurrentDirectorySetCurrentDirectorySHFileOperationSHFreeNameMappingsSHNAMEMAPPING

__________________________________________________________________________________________

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.

微信扫一扫

支付宝扫一扫

本文网址:https://www.zhankr.net/141469.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:875 阅读:5,067
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:806 阅读:3,504
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:565 阅读:4,312
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:730 阅读:4,307
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:4,904
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:3,097
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力内容变现

将您的收入提升到一个新的水平

点击联系客服

在线时间:8:00-16:00

客服电话

400-888-8888

客服邮箱

ceotheme@ceo.com

扫描二维码

关注微信公众号

扫描二维码

手机访问本站