SHFileOperation???怎么用???(50分)

  • 主题发起人 主题发起人 兔爷
  • 开始时间 开始时间
procedure TForm1.copybuttonClick(Sender: TObject);<br>var<br> F:TShFileOpStruct;<br>begin<br> F.wnd:=Handle;<br> F.wFunc:=FO—COPY; {操作方式}<br> F.pFrom:=′C:/DEMO.DAT′;<br> F.pTo:=′F:/TEST.DAT′;<br> F.fFlags:=FOF—ALLOWUNDO OR FOF—RENAMEONCOLLISION; {操作选项}<br> if ShFileOperation(F)&lt;&gt;0 then<br>  ShowMessage(′文件拷贝失败!′);<br>end;<br><br><br>函数说明在此:<br>WINSHELLAPI int WINAPI SHFileOperation(<br>&nbsp; &nbsp; LPSHFILEOPSTRUCT lpFileOp <br>); <br>Copies, moves, renames, or deletes a file system object. <br>Returns zero if successful, or nonzero otherwise. <br><br>lpFileOp <br>Address of an SHFILEOPSTRUCT structure that contains information <br>this function needs to carry out the specified operation. <br>
 
察看一下帮助就的了
 
需要注意一点是TShFileOpStruct中pFrom和pTo项必须以<br>双null结尾。
 
各位大虾:本人中文都没学好,鹦语就别提了……
 
但是你一定要看delphi提供的帮助,那是最权威的解释了.<br>wjiachun已经说明了函数用法,就是遵照shfileopstruct结构定义的参数去写就行<br>polygon说的也很好,你一定要注意如果对多文件进行操作,文件之间要用#0隔开,<br>最后一个文件要用#0#0结束,切记.
 
接受答案了.
 
Delhi帮助中没有耶
 
Contains information that the SHFileOperation function uses to perform file operations.<br><br>typedef struct _SHFILEOPSTRUCT { // shfos &nbsp;<br>&nbsp; &nbsp; HWND &nbsp; &nbsp; &nbsp; &nbsp; hwnd; <br>&nbsp; &nbsp; UINT &nbsp; &nbsp; &nbsp; &nbsp; wFunc; <br>&nbsp; &nbsp; LPCSTR &nbsp; &nbsp; &nbsp; pFrom; <br>&nbsp; &nbsp; LPCSTR &nbsp; &nbsp; &nbsp; pTo; <br>&nbsp; &nbsp; FILEOP_FLAGS fFlags; <br>&nbsp; &nbsp; BOOL &nbsp; &nbsp; &nbsp; &nbsp; fAnyOperationsAborted; <br>&nbsp; &nbsp; LPVOID &nbsp; &nbsp; &nbsp; hNameMappings; <br>&nbsp; &nbsp; LPCSTR &nbsp; &nbsp; &nbsp; lpszProgressTitle; <br>} SHFILEOPSTRUCT, FAR *LPSHFILEOPSTRUCT; <br>&nbsp;<br><br>Members<br><br>hwnd<br><br>Handle of the dialog box to use to display information about the status of the operation. <br><br>wFunc<br><br>Operation to perform. This member can be one of the following values:<br><br>FO_COPY Copies the files specified by pFrom to the location specified by pTo.<br>FO_DELETE Deletes the files specified by pFrom (pTo is ignored).<br>FO_MOVE Moves the files specified by pFrom to the location specified by pTo.<br>FO_RENAME Renames the files specified by pFrom. <br>&nbsp;<br><br>pFrom<br><br>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.<br><br>pTo<br><br>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.<br><br>fFlags<br><br>Flags that control the file operation. This member can be a combination of the following values:<br><br>FOF_ALLOWUNDO Preserves undo information, if possible.<br>FOF_CONFIRMMOUSE Not implemented.<br>FOF_FILESONLY Performs the operation only on files if a wildcard filename (*.*) is specified.<br>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.<br>FOF_NOCONFIRMATION Responds with "yes to all" for any dialog box that is displayed.<br>FOF_NOCONFIRMMKDIR Does not confirm the creation of a new directory if the operation requires one to be created.<br>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.<br>FOF_SILENT Does not display a progress dialog box.<br>FOF_SIMPLEPROGRESS Displays a progress dialog box, but does not show the filenames.<br>FOF_WANTMAPPINGHANDLE Fills in the hNameMappings member. The handle must be freed by using the SHFreeNameMappings function.<br>&nbsp;<br><br>fAnyOperationsAborted<br><br>Value that receives TRUE if the user aborted any file operations before they were completed or FALSE otherwise.<br><br>hNameMappings<br><br>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.<br><br>lpszProgressTitle<br><br>Pointer to a string to use as the title for a progress dialog box. This member is used only if fFlags includes FOF_SIMPLEPROGRESS.<br><br>&nbsp;<br><br>Remarks<br><br>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.<br><br>See Also<br><br>GetCurrentDirectory, SetCurrentDirectory, SHFileOperation, SHFreeNameMappings, SHNAMEMAPPING
 
后退
顶部