• 全部
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

高手指教,SHFileOperaton里的参数怎么设置

h3w4 2004-04-12 06:10:17
SHFileOperation(SHFILEOPSTRUCT& sfos);
我用的是delete操作
SHFILEOPSTRUCT中的pFrom很怪
如果我这样附值没问题
pForm = "d:\\tst.txt";
但是如果我改成这样,就总提示找不到牙什么的
char path[] = "d:\\tst.txt";
pForm = path;
如何搞定啊。。。。。。。
...全文
14 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
h3w4 2004-04-17
主要是我现在只知道PIDL,现在想做的动作是确定它是否是这两个文件夹,那么我怎么来确定呢
回复
byf2002 2004-04-13
它的说明是说:

你如果试图将本地这两个两个文件夹Remove到远程的某台机器上时,将抛出异常.

CSIDL_PERSONAL and CSIDL_MYPICTURES

这两个东东你直接用就行了.可能对应我的公文包和我的图片文件夹
回复
h3w4 2004-04-13
呵呵MSDN都搬出来了,谢谢了先,还有个问题,就是里边说的
CSIDL_PERSONAL and CSIDL_MYPICTURES,这两个东西对应的PIDL我怎么能确定呢
由CSIDL可以找到PIDL,通过SHFolderLocation就可以得到
那么反过来怎么由PIDL得到CSIDL呢,毕竟比较两个CSIDL更方便,更有效率些
回复
byf2002 2004-04-12
SHFILEOPSTRUCT
Contains information that the SHFileOperation function uses to perform file operations.



typedef struct _SHFILEOPSTRUCT{
HWND hwnd;
UINT wFunc;
LPCTSTR pFrom;
LPCTSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCSTR lpszProgressTitle;
} SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;

Members
hwnd
Window handle to the dialog box to display information about the status of the file operation.
wFunc
Value that indicates which operation to perform. This member can be one of the following values:
FO_COPY
Copy the files specified in the pFrom member to the location specified in the pTo member.
FO_DELETE
Delete the files specified in pFrom.
FO_MOVE
Move the files specified in pFrom to the location specified in pTo.
FO_RENAME
Rename the file specified in pFrom. You cannot use this flag to rename multiple files with a single function call. Use FO_MOVE instead.
pFrom
Address of a buffer to specify one or more source file names. These names must be fully qualified paths. Standard DOS wild cards, such as "*", are permitted in the filename position. Although this member is declared as a null-terminated string, it is used as a buffer to hold multiple file names. Each file name must be terminated by a single NULL character. An additional NULL character must be appended to the end of the final name to indicate the end of pFrom.
pTo
Address of a buffer to contain the name of the destination file or directory. This parameter must be set to NULL if it is not used. Like pFrom, the pTo member is also a double-NULL terminated string and is handled in much the same way. However, pTo must meet the following specifications:
Wildcard characters are not supported.
Copy and Move operations can specify destination directories that do not exist and the system will attempt to create them. The system normally displays a dialog box to ask the user if they want to create the new directory. To suppress this dialog box and have the directories created silently, set the FOF_NOCONFIRMDIR flag in fFiles.
For Copy and Move operations, the buffer can contain multiple destination file names if the fFlags member specifies FOF_MULTIDESTFILES.
Pack multiple names into the string in the same way as for pFrom.
Use only fully-qualified path names. Using relative pathnames will have unpredictable results.
fFlags
Flags that control the file operation. This member can take a combination of the following flags: Flag Description
FOF_ALLOWUNDO Preserve Undo information, if possible. If pFrom does not contain fully qualified path and file names, this flag is ignored.
FOF_FILESONLY Perform the operation on files only if a wildcard file name (*.*) is specified.
FOF_MULTIDESTFILES 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 Respond with "Yes to All" for any dialog box that is displayed.
FOF_NOCONFIRMMKDIR Do not confirm the creation of a new directory if the operation requires one to be created.
FOF_NO_CONNECTED_ELEMENTS Version 5.0. Do not move connected files as a group. Only move the specified files.
FOF_NOCOPYSECURITYATTRIBS Version 4.71. Do not copy the security attributes of the file.
FOF_NOERRORUI Do not display a user interface if an error occurs.
FOF_NORECURSION Only operate in the local directory. Don't operate recursively into subdirectories.
FOF_RENAMEONCOLLISION Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
FOF_SILENT Do not display a progress dialog box.
FOF_SIMPLEPROGRESS Display a progress dialog box but do not show the file names.
FOF_WANTMAPPINGHANDLE If FOF_RENAMEONCOLLISION is specified and any files were renamed, assign a name mapping object containing their old and new names to the hNameMappings member.
FOF_WANTNUKEWARNING Version 5.0. Send a warning if a file is being destroyed during a delete operation rather than recycled. This flag partially overrides FOF_NOCONFIRMATION.

fAnyOperationsAborted
Value that receives TRUE if the user aborted any file operations before they were completed, or FALSE otherwise.
hNameMappings
A handle to a name mapping object containing the old and new names of the renamed files. This member is used only if the fFlags member includes the FOF_WANTMAPPINGHANDLE flag. Treat hNameMappings as a pointer to a structure whose first member is an INT value, followed by an array of SHNAMEMAPPING structures. The INT value will be set to the number of structures in the array. Each SHNAMEMAPPING structure will contain the old and new path name for one of the renamed files.
Note: The handle must be freed with SHFreeNameMappings.

lpszProgressTitle
Address of a string to use as the title of a progress dialog box. This member is used only if fFlags includes the FOF_SIMPLEPROGRESS flag.
Remarks
If the pFrom or pTo members are unqualified names, the current directories are taken from the global current drive and directory settings as managed by the GetCurrentDirectory and SetCurrentDirectory functions.

If pFrom is set to a filename, deleting the file with FO_DELETE will not move it to the Recycle Bin, even if the FOF_ALLOWUNDO flag is set. You must use a full pathname.

回复
byf2002 2004-04-12
SHFileOperation
Copies, moves, renames, or deletes a file system object.



int SHFileOperation(
LPSHFILEOPSTRUCT lpFileOp
);


Parameters
lpFileOp
[in] Address of an SHFILEOPSTRUCT structure that contains information this function needs to carry out the specified operation.
Return Values
Returns zero if successful, or nonzero otherwise.

Remarks
You should use fully-qualified pathnames with this function. Using it with relative path-names is not thread-safe.

With two exceptions, you cannot use SHFileOperation to move special folders from a local drive to a remote computer by specifying a network path. The exceptions are the MyDocs and MyPics folders (CSIDL_PERSONAL and CSIDL_MYPICTURES, respectively).

When used to delete a file, SHFileOperation will attempt to place the deleted file in the Recycle Bin. If you wish to delete a file and guarantee that it will not be placed in the Recycle Bin, use DeleteFile.

If a copy callback handler is exposed and registered, SHFileOperation will call it unless you set a flag such as FOF_NOCONFIRMATION in the fFlags member of the structure pointed to by lpFileOp. See ICopyHook::CopyCallback for details on implementing copy callback handlers.

File deletion is recursive unless you set the FOF_NORECURSION flag in lpFileOp.

With Microsoft® Windows 2000® and later, it is possible to connect an HTML file with a folder containing related files such as GIF images or style sheets. If file connection is enabled, when you move or copy the HTML file, all of the files in the folder will be moved or copied as well. Conversely, if you move the folder with the related files, the HTML file is also moved.

The HTML file must have a .htm or .html extension. You create the connection to the related files by placing them in a subfolder of the folder containing the HTML file. The folder must have the name of the HTML file followed by " files". For example, if the HTML file is MyFile.htm, the folder should be named "MyFile files". Any files you place in the "MyFile files" subfolder will be connected to MyFile.htm.

File connection is enabled by default. It can be disabled by adding a REG_DWORD value, NoFileFolderConnection, to the HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer registry key. Setting NoFileFolderConnection to 1 disables file connection. If the value is set to zero or is missing, file connection is enabled.

To move only specified files from a group of connected files, set the FOF_ NO_CONNECTED_ELEMENTS flag in the fFlags member of the structure pointed to by lpFileOp.

Note that the use of a folder with a name like "MyFile files" to define a connection may not be valid for localized versions of Windows NT. The term "files" may need be replaced by the equivalent word in the local language.
回复
王国凡 2004-04-12
BOOL DeleteEx(LPCTSTR lpName,bool bRecover=false)
{
SHFILEOPSTRUCT fo;
fo.hwnd=NULL;
fo.hNameMappings=NULL;
fo.pFrom=lpName;
fo.pTo=NULL;
fo.wFunc=FO_DELETE;
fo.fFlags=FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
if(bRecover)
fo.fFlags|=FOF_ALLOWUNDO;

return SHFileOperation(&fo);
}

bRecover表示是否放到回收站。
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-04-12 06:10
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……