SumTingWong Posted May 26, 2005 Posted May 26, 2005 (edited) expandcollapse popupGlobal 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 Edited May 26, 2005 by SumTingWong
this-is-me Posted May 26, 2005 Posted May 26, 2005 Is there a way to specify multiple input sources? Who else would I be?
SumTingWong Posted May 26, 2005 Author Posted May 26, 2005 (edited) Is there a way to specify multiple input sources?<{POST_SNAPBACK}>pFromAddress of a buffer to specify one or more source file names. These names must be fully qualified paths. Standard Microsoft MS-DOS wild cards, such as "*", are permitted in the file-name 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.pToAddress 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_NOCONFIRMMKDIR flag in fFlags.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 paths. Using relative paths will have unpredictable results.Multiple sources support added. Edited May 26, 2005 by SumTingWong
SumTingWong Posted May 26, 2005 Author Posted May 26, 2005 Thank You, Mr. Wong.<{POST_SNAPBACK}>Nothing else wong?
hoppy Posted May 6, 2006 Posted May 6, 2006 very nice, aspecially with the multi input possibility. Would it be possible (probably yes but easy?) to adinn a flag to only copy newer files? So it can be used as a backup/sync tool? I've been trying but I'm loosing hope in my capabilities.
logonui Posted November 22, 2006 Posted November 22, 2006 (edited) I am getting this error message when i try to run the above code.Any ideas why?Any help would be appreciated Edited November 22, 2006 by logonui
piccaso Posted November 22, 2006 Posted November 22, 2006 (edited) DllStructDelete is gone.you could add this to the script as a workaroundFunc DllStructDelete(ByRef $vStruct) $vStruct = "" EndFunccheck out this post too Edited November 22, 2006 by piccaso CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
logonui Posted November 23, 2006 Posted November 23, 2006 DllStructDelete is gone. you could add this to the script as a workaround Func DllStructDelete(ByRef $vStruct) $vStruct = "" EndFunc check out this post too Cheers it works perfectly now
baghenamoth Posted June 4, 2007 Posted June 4, 2007 (edited) Hi, thx for this great function. Is there a flag to hide the cancel button and the system menu (minimize, maximize close) ? If no is there a way to intercept DllCall ? I don't know how to manipulate dll.. I try with running another script before _ExplorerCopy and it works but I'd like somthing clean WinWait("Calcul du temps restant...") ;french title of the copy dialog box ControlHide ("Calcul du temps restant...","","Button2") ;hidding the button Edited June 4, 2007 by baghenamoth
BrettF Posted April 8, 2008 Posted April 8, 2008 Hey, Sorry to bump an old post, but this is is such a good piece of code. I just want it to work. What I've got at the moment is the following: expandcollapse popupGlobal 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("F:\My Documents\Backups\files\Bus Driver " & @LF & " F:\Program Files\Valve", "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 $pFrom = 0 $pTo = 0 $SHFILEOPSTRUCT = 0 If $nError <> 0 Then SetError($nError) Return False EndIf Return True EndFunc Pretty much exactly the original, but updated. Now why does it not work?? I can get 1 file working, but not the 2. I'll try to get it to work, but if anyone has a fix it would be apriciated. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
BrettF Posted April 8, 2008 Posted April 8, 2008 (edited) Got It! Just used $n = _CopyWithProgress("F:\My Documents\Backups\files\Bus Driver" & Chr (0x00) & "F:\Program Files\Valve", "D:\DestDir") EDIT: Well it works for the first folder... Edited April 8, 2008 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
BrettF Posted April 11, 2008 Posted April 11, 2008 Bump my question... No answers? I still can't work it out... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Zedna Posted May 26, 2008 Posted May 26, 2008 Now I need to use this function in my project and it really doesn't work for more than one input source.After some debugging and trying I have found BUG and created FIX:expandcollapse popupGlobal 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 $n = _CopyWithProgress("F:\My Documents\Backups\files\Bus Driver" & @LF & "F:\Program Files\Valve", "D:\DestDir") ;~ If Not $n Then ConsoleWrite('error:' & @error & @CRLF) Func _CopyWithProgress($sFrom, $sTo) Local $SHFILEOPSTRUCT, $pFrom, $pTo, $aDllRet, $i, $nError = 0 $SHFILEOPSTRUCT = DllStructCreate("hwnd hwnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle") DllStructSetData($SHFILEOPSTRUCT, "hwnd", 0) DllStructSetData($SHFILEOPSTRUCT, "wFunc", $FO_COPY) $pFrom = DllStructCreate("char[" & StringLen($sFrom)+2 & "]") DllStructSetData($pFrom, 1, $sFrom) For $i = 1 To StringLen($sFrom)+2 If DllStructGetData($pFrom, 1, $i) = Chr(10) Then DllStructSetData($pFrom, 1, Chr(0), $i) Next DllStructSetData($pFrom, 1, Chr(0), StringLen($sFrom)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pFrom", DllStructGetPtr($pFrom)) $pTo = DllStructCreate("char[" & StringLen($sTo)+2 & "]") DllStructSetData($pTo, 1, $sTo) DllStructSetData($pTo, 1, Chr(0), StringLen($sTo)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pTo", DllStructGetPtr($pTo)) DllStructSetData($SHFILEOPSTRUCT, "fFlags", BitOR($FOF_NOCONFIRMMKDIR, $FOF_NOCONFIRMATION, $FOF_NOERRORUI)) DllStructSetData($SHFILEOPSTRUCT, "fAnyOperationsAborted", 0) DllStructSetData($SHFILEOPSTRUCT, "hNameMappings", 0) DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", 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 ; test if button Abort was pressed If DllStructGetData($SHFILEOPSTRUCT, "fAnyOperationsAborted") Then $nError = -1 $pFrom = 0 $pTo = 0 $SHFILEOPSTRUCT = 0 If $nError <> 0 Then SetError($nError) Return False EndIf Return True EndFuncNote: - you can use also fileName/filenames with full path as source file. - fAnyOperationsAborted not testedHere is MSDN link:http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspxhttp://msdn.microsoft.com/en-us/library/bb759795(VS.85).aspx Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search
Zedna Posted May 26, 2008 Posted May 26, 2008 And here is simplified version when you call it with Chr(0) instead of @LF: expandcollapse popupGlobal 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 $n = _CopyWithProgress("F:\My Documents\Backups\files\Bus Driver" & Chr(0) & "F:\Program Files\Valve", "D:\DestDir") ;~ If Not $n Then ConsoleWrite('error:' & @error & @CRLF) Func _CopyWithProgress($sFrom, $sTo) Local $SHFILEOPSTRUCT, $pFrom, $pTo, $aDllRet, $nError = 0 $SHFILEOPSTRUCT = DllStructCreate("hwnd hwnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle") DllStructSetData($SHFILEOPSTRUCT, "hwnd", 0) DllStructSetData($SHFILEOPSTRUCT, "wFunc", $FO_COPY) $pFrom = DllStructCreate("char[" & StringLen($sFrom)+2 & "]") DllStructSetData($pFrom, 1, $sFrom) DllStructSetData($pFrom, 1, Chr(0), StringLen($sFrom)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pFrom", DllStructGetPtr($pFrom)) $pTo = DllStructCreate("char[" & StringLen($sTo)+2 & "]") DllStructSetData($pTo, 1, $sTo) DllStructSetData($pTo, 1, Chr(0), StringLen($sTo)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pTo", DllStructGetPtr($pTo)) DllStructSetData($SHFILEOPSTRUCT, "fFlags", BitOR($FOF_NOCONFIRMMKDIR, $FOF_NOCONFIRMATION, $FOF_NOERRORUI)) DllStructSetData($SHFILEOPSTRUCT, "fAnyOperationsAborted", 0) DllStructSetData($SHFILEOPSTRUCT, "hNameMappings", 0) DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", 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 ; test if button Abort was pressed If DllStructGetData($SHFILEOPSTRUCT, "fAnyOperationsAborted") Then $nError = -1 $pFrom = 0 $pTo = 0 $SHFILEOPSTRUCT = 0 If $nError <> 0 Then SetError($nError) Return False EndIf Return True EndFunc Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search
Zedna Posted May 27, 2008 Posted May 27, 2008 I have problems with using lpszProgressTitle struct param. I have always memory read/write error message. I tried every possible combinations.Please can somebody help me with this?this script is without constants (they are the same as in above scripts):expandcollapse popup$n = _CopyWithProgress("F:\My Documents\Backups\files\Bus Driver" & Chr(0) & "F:\Program Files\Valve", "D:\DestDir", "Test Title...") Func _CopyWithProgress($sFrom, $sTo, $sTitle = '') Local $SHFILEOPSTRUCT, $pFrom, $pTo, $pTitle, $aDllRet, $nError = 0 Local $flags = BitOR($FOF_NOCONFIRMMKDIR, $FOF_NOCONFIRMATION, $FOF_NOERRORUI) $SHFILEOPSTRUCT = DllStructCreate("hwnd hwnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle") DllStructSetData($SHFILEOPSTRUCT, "hwnd", 0) DllStructSetData($SHFILEOPSTRUCT, "wFunc", $FO_COPY) $pFrom = DllStructCreate("char[" & StringLen($sFrom)+2 & "]") DllStructSetData($pFrom, 1, $sFrom) DllStructSetData($pFrom, 1, Chr(0), StringLen($sFrom)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pFrom", DllStructGetPtr($pFrom)) $pTo = DllStructCreate("char[" & StringLen($sTo)+2 & "]") DllStructSetData($pTo, 1, $sTo) DllStructSetData($pTo, 1, Chr(0), StringLen($sTo)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pTo", DllStructGetPtr($pTo)) DllStructSetData($SHFILEOPSTRUCT, "fAnyOperationsAborted", 0) DllStructSetData($SHFILEOPSTRUCT, "hNameMappings", 0) If $sTitle <> '' Then $pTitle = DllStructCreate("char[" & StringLen($sTitle)+1 & "]") ;$pTitle = DllStructCreate("char[4]") DllStructSetData($pTitle, 1, $sTitle) ;DllStructSetData($pTitle, 1, 'aaa') DllStructSetData($pTitle, 1, Chr(0), StringLen($sTitle)+1) ; null at the end $flags = BitOR($flags, $FOF_SIMPLEPROGRESS) DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", DllStructGetPtr($pTitle)) ;~ DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", 'aaa') Else DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", 0) EndIf DllStructSetData($SHFILEOPSTRUCT, "fFlags", $flags) $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 ; test if button Abort was pressed If DllStructGetData($SHFILEOPSTRUCT, "fAnyOperationsAborted") Then $nError = -1 $pFrom = 0 $pTo = 0 $pTitle = 0 $SHFILEOPSTRUCT = 0 If $nError <> 0 Then SetError($nError) Return False EndIf Return True EndFunc Resources UDF  ResourcesEx UDF  AutoIt Forum Search
kjcdude Posted October 10, 2008 Posted October 10, 2008 Does anyone have a version working with filecopy instead of dircopy? Thanks
mrmacadamia Posted December 4, 2009 Posted December 4, 2009 And here is simplified version when you call it with Chr(0) instead of @LF: expandcollapse popupGlobal 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 $n = _CopyWithProgress("F:\My Documents\Backups\files\Bus Driver" & Chr(0) & "F:\Program Files\Valve", "D:\DestDir") ;~ If Not $n Then ConsoleWrite('error:' & @error & @CRLF) Func _CopyWithProgress($sFrom, $sTo) Local $SHFILEOPSTRUCT, $pFrom, $pTo, $aDllRet, $nError = 0 $SHFILEOPSTRUCT = DllStructCreate("hwnd hwnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle") DllStructSetData($SHFILEOPSTRUCT, "hwnd", 0) DllStructSetData($SHFILEOPSTRUCT, "wFunc", $FO_COPY) $pFrom = DllStructCreate("char[" & StringLen($sFrom)+2 & "]") DllStructSetData($pFrom, 1, $sFrom) DllStructSetData($pFrom, 1, Chr(0), StringLen($sFrom)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pFrom", DllStructGetPtr($pFrom)) $pTo = DllStructCreate("char[" & StringLen($sTo)+2 & "]") DllStructSetData($pTo, 1, $sTo) DllStructSetData($pTo, 1, Chr(0), StringLen($sTo)+2) ; second null at the end DllStructSetData($SHFILEOPSTRUCT, "pTo", DllStructGetPtr($pTo)) DllStructSetData($SHFILEOPSTRUCT, "fFlags", BitOR($FOF_NOCONFIRMMKDIR, $FOF_NOCONFIRMATION, $FOF_NOERRORUI)) DllStructSetData($SHFILEOPSTRUCT, "fAnyOperationsAborted", 0) DllStructSetData($SHFILEOPSTRUCT, "hNameMappings", 0) DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", 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 ; test if button Abort was pressed If DllStructGetData($SHFILEOPSTRUCT, "fAnyOperationsAborted") Then $nError = -1 $pFrom = 0 $pTo = 0 $SHFILEOPSTRUCT = 0 If $nError <> 0 Then SetError($nError) Return False EndIf Return True EndFunc yet another sorry for bumping old post. I'm searching the way to use dircopy without my gui being freezed. I found this thread and tried your code it work except that I think I found a bug. $n = _CopyWithProgress(@DesktopDir, @MyDocumentsDir & "\desktopbackup") It doesn't copy the desktop dir, but it worked if use another macro like @programfiles which I think it might be the macro problem. Unless I use fake dir(which the dir not even exist) like this $n = _CopyWithProgress(@DesktopDir & Chr(0) & "c:\fake", @MyDocumentsDir & "\desktopbackup") It will copy the desktop dir. thanks
bob31334 Posted February 13, 2012 Posted February 13, 2012 An updated version of the original post. This catches the user pressing 'Cancel' while copying. The primary difference is in the definition of the struct. The idea for this came from this postexpandcollapse popupGlobal 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 Func _CopyWithProgress($sFrom, $sTo) Local $SHFILEOPSTRUCT Local $pFrom Local $pTo Local $aDllRet Local $nError = 0 Local $i $SHFILEOPSTRUCT = DllStructCreate("align 1;hwnd;uint;ptr;ptr;ushort;bool;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 Dim $aborted = DllStructGetData($SHFILEOPSTRUCT, 6) DllStructDelete($pFrom) DllStructDelete($pTo) DllStructDelete($SHFILEOPSTRUCT) If $nError <> 0 Then SetError($nError) Return False elseif $aborted Then Return False EndIf Return True EndFunc Func DllStructDelete(ByRef $vStruct) $vStruct = "" EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now