用API复制移动文件 RRS feed

  • 常规讨论

  • Public Const FOF_SILENT As Long = &H4

    Public Const FOF_RENAMEONCOLLISION As Long = &H8

    Public Const FOF_NOCONFIRMATION As Long = &H10

    Public Const FOF_WANTMAPPINGHANDLE As Long = &H20

    Public Const FOF_CREATEPROGRESSDLG As Long = &H0

    Public Const FOF_ALLOWUNDO As Long = &H40

    Public Const FOF_FILESONLY As Long = &H80

    Public Const FOF_SIMPLEPROGRESS As Long = &H100

    Public Const FOF_NOCONFIRMMKDIR As Long = &H200

    '2 。在form1中添加以下代码以及一个commandbox:

    Private Sub Command1_Click()


    Dim result As Long

    With DelFileOp

    .hwnd = Me.hwnd

    .wFunc = FO_DELETE '(删除)

    '.wfunc=fo_rename(改名) fo_move(移动) fo_copy(拷贝)

    ' Delete the files you just moved to C:\TestFolder.

    ' If you do not have these files, you can alter this

    ' sample to point to existing files.

    ' .pFrom = "C:\testfolder\file1" & vbNullChar & "c:\testfolder\file2" & vbNullChar & vbNullChar

    .pFrom = "d:\testfolder\*" & vbNullChar & vbNullChar

    '.pTo = "d:\test" (移动,拷贝时有效)

    ' Allow undo--in other words, place the files into the Recycle Bin

    .fFlags = FOF_ALLOWUNDO

    End With

    result = SHFileOperation(DelFileOp)

    If result <> 0 Then ' Operation failed

    If Err.LastDllError <> 0 Then

    MsgBox Err.LastDllError ' Msgbox the error that occurred in the API.

    End If


    If DelFileOp.fAnyOperationsAborted <> 0 Then

    MsgBox "Operation Failed"

    End If

    End If

    End Sub
    2009年5月27日 8:33