Jump to content

SHFileOperation


Recommended Posts

SumTingWong proposed this very insterresting script to copy fiels with progress

http://www.autoitscript.com/forum/index.ph...SHFileOperation

Global Const $FO_MOVE                   = 0x0001
Global Const $FO_COPY                   = 0x0002
Global Const $FO_DELETE                 = 0x0003
Global Const $FO_RENAME                 = 0x0004

Global Const $FOF_MULTIDESTFILES        = 0x0001
Global Const $FOF_CONFIRMMOUSE          = 0x0002
Global Const $FOF_SILENT                = 0x0004
Global Const $FOF_RENAMEONCOLLISION     = 0x0008
Global Const $FOF_NOCONFIRMATION        = 0x0010
Global Const $FOF_WANTMAPPINGHANDLE     = 0x0020
Global Const $FOF_ALLOWUNDO             = 0x0040
Global Const $FOF_FILESONLY             = 0x0080
Global Const $FOF_SIMPLEPROGRESS        = 0x0100
Global Const $FOF_NOCONFIRMMKDIR        = 0x0200
Global Const $FOF_NOERRORUI             = 0x0400
Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x0800
Global Const $FOF_NORECURSION           = 0x1000
Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000
Global Const $FOF_WANTNUKEWARNING       = 0x4000
Global Const $FOF_NORECURSEREPARSE      = 0x8000

Dim $n

$n = _CopyWithProgress("C:\SourceDir1" & @LF & "C:\SourceDir2", "D:\DestDir")

Func _CopyWithProgress($sFrom, $sTo)
    Local $SHFILEOPSTRUCT
    Local $pFrom
    Local $pTo
    Local $aDllRet
    Local $nError = 0
    Local $i
    
    $SHFILEOPSTRUCT = DllStructCreate("int;uint;ptr;ptr;uint;int;ptr;ptr")
    If @error Then Return False        
; hwnd
    DllStructSetData($SHFILEOPSTRUCT, 1, 0)
; wFunc
    DllStructSetData($SHFILEOPSTRUCT, 2, $FO_COPY)
; pFrom
    $pFrom = DllStructCreate("char[" & StringLen($sFrom)+2 & "]")
; pFrom will now be null-terminated at StringLen($sFrom)+1
    DllStructSetData($pFrom, 1, $sFrom)
    For $i = 1 To StringLen($sFrom)+2
        If DllStructGetData($pFrom, 1, $i) = 10 Then DllStructSetData($pFrom, 1, 0, $i)
    Next
; We need a second null at the end
    DllStructSetData($pFrom, 1, 0, StringLen($sFrom)+2)
    DllStructSetData($SHFILEOPSTRUCT, 3, DllStructGetPtr($pFrom))
; pTo
    $pTo = DllStructCreate("char[" & StringLen($sTo)+2 & "]")
; pTo will now be null-terminated at StringLen($sTo)+1
    DllStructSetData($pTo, 1, $sTo)
; We need a second null at the end
    DllStructSetData($pTo, 1, 0, StringLen($sTo)+2)
    DllStructSetData($SHFILEOPSTRUCT, 4, DllStructGetPtr($pTo))
; fFlags
    DllStructSetData($SHFILEOPSTRUCT, 5, BitOR($FOF_NOCONFIRMMKDIR, _
        $FOF_NOCONFIRMATION, _
        $FOF_NOERRORUI))
; fAnyOperationsAborted
    DllStructSetData($SHFILEOPSTRUCT, 6, 0)
; hNameMappings
    DllStructSetData($SHFILEOPSTRUCT, 7, 0)
; lpszProgressTitle
    DllStructSetData($SHFILEOPSTRUCT, 8, 0)
    $aDllRet = DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($SHFILEOPSTRUCT))
    If @error Or $aDllRet[0] <> 0 Then
        $aDllRet = DllCall("kernel32.dll", "long", "GetLastError")
        If Not @error Then $nError = $aDllRet[0]
    EndIf
    DllStructDelete($pFrom)
    DllStructDelete($pTo)
    DllStructDelete($SHFILEOPSTRUCT)
    If $nError <> 0 Then
        SetError($nError)
        Return False
    EndIf
    Return True
EndFunc
oÝ÷ Ø-êÞiùZÚ!×­çÇ¥nëm¢v§vØ^³+-zié¢)¢ÍéÆ)¢Íç%¢Ç~z"²Ø^­æ°k+h{^­Ç©´9e ©e!Ú'ßÛd!£h©â¦éZµçekË­»§)àjz-êìr¸©µ·¢·Æh­ê¢حÂä±»­#])²­)àrW«­¢+Ø)]¥¹]¥Ð ÅÕ½Ðí
±Õ°ÔѵÁÌÉÍѹи¸¸ÅÕ½Ðì¤íɹ ѥѱ½Ñ¡½Á䥱½½à)
½¹Ñɽ±!¥ ÅÕ½Ðí
±Õ°ÔѵÁÌÉÍѹи¸¸ÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí    ÕÑѽ¸ÈÅÕ½Ðì¤í¡¥¥¹Ñ¡ÕÑѽ¸
Link to comment
Share on other sites

if you just want to stop user interaction use: BlockInput () before and after the copy routine.

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...