q4q Posted May 13, 2007 Posted May 13, 2007 Does anyone know why SumTingWong's script (below) is failing? It works with everything up to and inc. beta 3.2.3.2 but fails with everything I've checked beyond this inc. latest public 3.2.4.1. Error displayed when flag $FOF_NOERRORUI is omitted is 'Cannot copy file: Cannot read from the source file or disk.' Thanks. CODEGlobal 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 ;==>_CopyWithProgress Func DllStructDelete(ByRef $vStruct) $vStruct = "" EndFunc ;==>DllStructDelete
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