希望大家不要深入的探讨一下,如Wnd,pTo,wFunc,fFlags,fAnyOperationsAborted,hNameMappings,lpszProgressTitle 这些参数的具体意义及用法,或者推荐一篇关于这个函数的详细介绍,我发现一些网上的关于这个函数的介绍只是泛泛的讲了一下,含糊的很,建议这个函数用处比较大,希望大家踊跃参与,把这个函数的各种用法写全,希望把此贴加入精华贴。
由于偶对此函数不太了解,所以只能简单介绍一下此函数的用法,在用此函数的时候必须先use ShellApi
此函数主要实现了windows下面的文件批量删除、复制、剪切功能,希望各位大侠详细介绍一下此函数的用法,分大大的,如不够我可以再开贴散分。

解决方案 »

  1.   

    本人查了一下Msdn,已经解决,呵呵
    SHFILEOPSTRUCT
    typedef struct _SHFILEOPSTRUCT{ 
        HWND         hwnd; 
        UINT         wFunc; 
        LPCSTR       pFrom; 
        LPCSTR       pTo; 
        FILEOP_FLAGS fFlags; 
        BOOL         fAnyOperationsAborted; 
        LPVOID       hNameMappings; 
        LPCSTR       lpszProgressTitle; 
    } SHFILEOPSTRUCT, FAR *LPSHFILEOPSTRUCT; 
     
    Contains information that the SHFileOperation function uses to perform file operations. hwnd 
    Window handle to the dialog box to display information about the status of the file operation. 
    wFunc 
    Operation to perform. This member can be one of the following values: FO_COPY  Copies the files specified in the pFrom member to the location specified in the pTo member. 
    FO_DELET  Deletes the files specified in pFrom. (pTo is ignored.) 
    FO_MOVE  Moves the files specified in pFrom to the location specified in pTo. 
    FO_RENAME  Renames the files specified in pFrom.  pFrom 
    Address of a buffer to specify one or more source file names. Multiple names must be null-separated. The list of names must be double null-terminated. 
    pTo 
    Address of a buffer to contain the name of the destination file or directory. The buffer can contain multiple 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 flags: FOF_ALLOWUNDO  Preserve Undo information, if possible. If pFrom does not contain fully qualified path and filenames, this flag is ignored.  
    FOF_CONFIRMMOUSE  Not currently implemented.  
    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  Does not confirm the creation of a new directory if the operation requires one to be created.  
    FOF_NOCOPYSECURITYATTRIBS  Version 4.71. Microsoft® Windows NT® only. The security attributes of the file will not be copied.  
    FOF_NOERRORUI  No user interface will be displayed if an error occurs.  
    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  Does not display a progress dialog box.  
    FOF_SIMPLEPROGRESS  Displays a progress dialog box but does not show the file names.  
    FOF_WANTMAPPINGHANDLE  If FOF_RENAMEONCOLLISION is specified, the hNameMappings member will be filled in if any files were renamed.  fAnyOperationsAborted 
    Value that receives TRUE if the user aborted any file operations before they were completed, or FALSE otherwise. 
    hNameMappings 
    Handle to a file name 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 the fFlags member includes the FOF_WANTMAPPINGHANDLE flag. The handle must be freed by using the SHFreeNameMappings function. 
    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. 
    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 theGetCurrentDirectory andSetCurrentDirectory functions. 
    SHFileOperation
    WINSHELLAPI int WINAPI SHFileOperation(
        LPSHFILEOPSTRUCT lpFileOp
    ); Copies, moves, renames, or deletes a file system object. Returns zero if successful, or nonzero otherwise. 
    lpFileOp 
    Address of an SHFILEOPSTRUCT structure that contains information this function needs to carry out the specified operation.
    希望英文好的大侠翻译一下
      

  2.   

    呵呵
    其实有些时候自己动动脑子
    问题也就解决了
    另外《delphi5 开发人员指南》里面对SHFileOperation也有比较详细的说明
      

  3.   

    是否知道世界上有种东西叫做MSDN
      

  4.   

    SHFileOperation
    WINSHELLAPI int WINAPI SHFileOperation(
        LPSHFILEOPSTRUCT lpFileOp
    ); Copies, moves, renames, or deletes a file system object. 
    复制/移动/重命名/删除一个FSO
    Returns zero if successful, or nonzero otherwise. 
    成功就返回0,否则返回非0
    lpFileOp 参数
    Address of an SHFILEOPSTRUCT structure that contains information this function needs to carry out the specified operation.
    一个包含了需要进行操作的SHFILEOPSTRUCT结构信息的指针
      

  5.   

    ehom(?!) 老兄说话真有意思
      

  6.   

    Copies, moves, renames, or deletes a file system object. 
    复制/移动/重命名/删除一个FSO
    Returns zero if successful, or nonzero otherwise. 
    成功就返回0,否则返回非0
    lpFileOp 参数
    Address of an SHFILEOPSTRUCT structure that contains information this function needs to carry out the specified operation.
    一个包含了需要进行操作的SHFILEOPSTRUCT结构信息的指针
      

  7.   

    我错了,原来楼主早就知道了MSDN这好东东多此一举,画蛇添足~~~
      

  8.   

    可以拷贝全目录啊,这个函数真好。
    想当初我刚开始工作那会儿,竟然用了个递归算法才实现了这个东东。《delphi5 开发人员指南》390页有对这个函数的说明。
      

  9.   

    这个
    hwnd 
    Window handle to the dialog box to display information about the status of the file operation. 
    有点蹊跷啊,帮你试一下。
      

  10.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      SHFileOpStruct:TSHFileOpStruct;
      rtn:integer;
    begin
      //说明如下:这个handle的意思是,信息对话框(系统自动调用的)的宿主句柄
      //如上,则是模式窗口的信息框,如 SHFileOpStruct.Wnd := 0;则非模式状态。
      SHFileOpStruct.Wnd := Handle;
      SHFileOpStruct.wFunc := FO_COPY;  //说明略
      SHFileOpStruct.pFrom := pchar('c:\1'); //说明略
      SHFileOpStruct.pTo := pchar('c:\2');  //说明略
      SHFileOpStruct.fFlags := FOF_NOCONFIRMATION + FOF_RENAMEONCOLLISION+FOF_SIMPLEPROGRESS ;
      //在设置 FOF_SIMPLEPROGRESS 的fFlags后会在信息框的文件名部位显示,
      //假如没有设置 FOF_SIMPLEPROGRESS ,则默认显示的是正在操作的文件名
      SHFileOpStruct.lpszProgressTitle := 'hello';
      //还未研究,略
      SHFileOpStruct.hNameMappings := nil;
      rtn := SHFileOperation(SHFileOpStruct);
      if rtn=0 then showmessage('victory');
    end;为了看到那个信息框,在文件夹中包涵了个大块头,差点没把我c盘给撑破了。哈哈