chaoticyeshua Posted October 18, 2012 Share Posted October 18, 2012 Sorry for the big bump. I'm using the code posted by Seeker in the post above mine to back up directories in a user's profile. I am backing up folders such as Desktop, Documents, Favorites, AppData\Roaming\Microsoft\Outlook, etc. The backup process works without any issues (at least, none that I've encountered). The problem comes when I use the same code to restore those folders from a backup. For example, this morning I used my backup script to back up a lady's profile. After reinstalling Windows and using my restore script, it seemingly goes okay. The script does not return false, so there wasn't an error reported or a cancellation. However, it only copied about half of the user's folders in her Documents folder. Here's a section of my code. $documents=_CopyWithProgress($backupprofile & "\Documents\*.*", $profiledir & "\Documents") If $documents=false Then _ArrayAdd($_failedRestores,"Documents") EndIf Where $backupprofile points to X:\_backup\ComputerName\UserName $profiledir is just @UserProfileDir stored into a variable. If I don't do *.* then it just copies the backed up Documents folder into their Documents folder, thus creating Documents\Documents. Is there either a way to prevent the sub-folder creation by using this script OR to resolve the weird copying issues with *.*? *.*, by the way, seems to work with other folders like Desktop, Favorites, etc. I've only encountered this problem with Documents. I don't know why. Link to comment Share on other sites More sharing options...
chaoticyeshua Posted October 19, 2012 Share Posted October 19, 2012 Nevermind. I'm just changing the line to: $documents=_CopyWithProgress($backupprofile & "\Documents", $profiledir) And if it detects XP: DirMove($backupprofile & "\Documents",$backupprofile & "\My Documents") $documents=_CopyWithProgress($backupprofile & "\My Documents", $profiledir) That seems to work okay in my testing so far. Link to comment Share on other sites More sharing options...
BrewManNH Posted October 19, 2012 Share Posted October 19, 2012 There's a macro for the documents folder that points to the correct location regardless of which OS you're on, @MyDocumentsDir. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
chaoticyeshua Posted October 21, 2012 Share Posted October 21, 2012 I would use that, but the script's purpose is to get a list of all local profiles, have checkboxes for them in a GUI, and back up folders in each one that is selected. So not necessarily just the currently logged in account. Link to comment Share on other sites More sharing options...
BrewManNH Posted October 21, 2012 Share Posted October 21, 2012 You could take a look at the link in my signature for a script I threw together to do something similar, the link to "Back up and restore Windows user files" might give you some ideas. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
chaoticyeshua Posted October 22, 2012 Share Posted October 22, 2012 Thanks! I'll take a look at it. Link to comment Share on other sites More sharing options...
ledigeine Posted November 1, 2012 Share Posted November 1, 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 post 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 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 When using this one here, when i tell it the location to copy. It copies the folder im selecting, and not the items int he folder im selecting. Say i have a folder c:junk and in junk is folder 'stuff' and file 'thing.exe'. When i tell DIRCOPY to copy c:junk it will copy 'stuff' and 'thing.exe' to the location i want. But if i use the above fuction it will copy 'junk' to the location, how would i make it copy its contents as opposed to the folder itself? Link to comment Share on other sites More sharing options...
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