mr-es335 Posted February 23 Posted February 23 (edited) Good day, I have two scripts, one that works with multiple file paths, and one that, at preset, only works with a single data path. I have been attempting, rather unsuccessfully, to update the 2nd script to do what the 1st scripts is doing. Any ideas on how to make the 2nd script employ multiple data paths? Here is the 1st script: Spoiler expandcollapse popup; ----------------------------------------------- #include "ExtMsgBox.au3" #include <FileConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $iEMBWidth = 400 Global $iMsgDelay = 1 ; ----------------------------------------------- BackupCopyDeleteRestoreShell() ; ----------------------------------------------- Func BackupCopyDeleteRestoreShell() Local $Type = " type data process [P#] is in progress..." Local $sMsg0 = "The Procedure # data WAS NOT process successfully!" Local $sMsg1 = "The Procedure # data WAS process successfully!" ; ----------------- Local $iStart = 5, $iEnd = 4 Local $sSrcPath[$iStart] = [$iEnd] Local $sDstPath[$iStart] = [$iEnd] ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", $iEMBWidth) ; ----------------------------------------------- $sSrcPath[1] = "" $sSrcPath[2] = "" $sSrcPath[3] = "" $sSrcPath[4] = "" ; ----------------- $sDstPath[1] = "" $sDstPath[2] = "" $sDstPath[3] = "" $sDstPath[4] = "" ; ----------------------------------------------- For $i = 1 To $sSrcPath[0] Local $sResult = FileCopy($sSrcPath[$i], $sDstPath[$i], $FC_OVERWRITE) ; ----------------------------------------------- If $sResult = 0 Then Local $sMsg = $sMsg0 _ExtMsgBox(64, " ", $Type, $sMsg, $iMsgDelay) ElseIf $sResult = 1 Then Local $sMsg = $sMsg1 _ExtMsgBox(64, " ", $Type, $sMsg, $iMsgDelay) EndIf Next EndFunc ;==>BackupCopyDeleteRestoreShell ; ----------------------------------------------- ...and here is the 2nd script: Spoiler expandcollapse popup; ----------------------------------------------- #include "ExtMsgBox.au3" #include <File.au3> ; ----------------------------------------------- Global $iMsgDelay = 2 Global $sProcedure = " " ; ----------------------------------------------- TypeDataProcess() ; ----------------------------------------------- Func TypeDataProcess() Local $sResult0Msg = "No type data was found...or the type data does not exist!" Local $sResult1Msg = "The type data was processed successfully!" ; ----------------- Local $sSrcPath = "" Local $sDstPath = "" ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold") ; ----------------------------------------------- ;~ Local $aFiles = _FileListToArrayRec($sSrcPath, "*", $FLTAR_FILES) ;~ Local $aFolders = _FileListToArrayRec($sSrcPath, "*", $FLTAR_FOLDERS) ; ----------------------------------------------- If @error Then _ExtMsgBox(48, " ", $sProcedure, $sResult0Msg, $iMsgDelay) Exit EndIf ; ----------------------------------------------- ;~ For $i = 1 To $aFiles[0] ;~ FileCopy($sSrcPath & "\" & $aFiles[$i], $sDstPath[$i] & "\" & $aFiles[$i], 1) ;~ Next ;~ For $i = 1 To $aFolders[0] ;~ DirCopy($sSrcPath & "\" & $aFolders[$i], $sDstPath[$i] & "\" & $aFolders[$i], 1) ;~ Next ; ----------------------------------------------- _ExtMsgBox(64, " ", " Notice!", $sResult1Msg, $iMsgDelay) EndFunc ;==>TypeDataProcess ; ----------------------------------------------- Note: In the 2nd script, I have commented-out those lines to select between file backup or folder backup - as very rarely do I have to backup both at the same time. Here is some testing" ;~ $aSrcPath[$i][1] = FileExists($aSrcPath[$i][0]) ? "...Yes " : "...No " ; Works! ;~ $aSrcPath[$i][1] = FileDelete($aSrcPath[$i][0]) ? "...Yes " : "...No " ; Works! ;~ $aSrcPath[$i][1] = FileCopy($aSrcPath[$i][0], $DstPath, 1) ? "...Yes " : "...No " ; Does NOT work! Edited February 23 by mr-es335 mr-es335 Sentinel Music Studios
mr-es335 Posted February 24 Author Posted February 24 Hello, With a little "bit 'o'help" from aye-eye: ;~ $FLTA_FILESFOLDERS (0) = (Default) Return both files and folders ;~ $FLTA_FILES (1) = Return files only ;~ $FLTA_FOLDERS (2) = Return Folders only #include <File.au3> Global $sourceFolder = "C:\Program Files\Native Instruments" Global $backupFolder = "D:\Important_Data\Testing\Backup\Data\Native Instruments" ; Run the backup function BackupFiles() ; Function to perform the backup Func BackupFiles() Local $fileList = _FileListToArray($sourceFolder, "*.*", $FLTA_FILESFOLDERS) If @error Then MsgBox(0, "Error", "Failed to list files in the source folder.") Return EndIf For $i = 1 To $fileList[0] Local $sourceFile = $sourceFolder & "\" & $fileList[$i] ConsoleWrite($fileList[$i] & @CRLF) Local $destFile = $backupFolder & "\" & $fileList[$i] ; Copy the file and check for errors If Not DirCopy($sourceFile, $destFile, 1) Then MsgBox(0, "Error", "Failed to copy " & $fileList[$i]) EndIf Next MsgBox(0, "Backup Complete", "All folders have been backed up.") EndFunc ;==>BackupFiles mr-es335 Sentinel Music Studios
mr-es335 Posted February 24 Author Posted February 24 (edited) Okay, How can the above be employed for BOTH files and folders? Or, would 2 scripts need to be created - one for files and one for folders? [I do believe the latter is what would be required?] If so, what is the purpose of: ;~ $FLTA_FILESFOLDERS (0) = (Default) Return both files and folders ;~ $FLTA_FILES (1) = Return files only ;~ $FLTA_FOLDERS (2) = Return Folders only Edited February 24 by mr-es335 mr-es335 Sentinel Music Studios
ioa747 Posted February 24 Posted February 24 The paradox here is that in order to help you, I need your help. That's why there is no answer in your thread. The snippets you provide, being inconsistent and lacking in essential elements, confuse the situation more than they explain it. You need to get into the process and explain it to us, because if you don't, who will? To provide you with a working solution, please clarify the following: In your first scenario, the paths are defined in a static array. In the second, you use _FileListToArray to dynamically scan a path. What is your ultimate goal? In any backup scenario, the essential elements are simple: $sSource and $sDestination. Do we have these clearly defined? Are there any quirks (such as specific file extensions or skipping subfolders)? If you just need to copy data, why can't a simple DirCopy($sSource, $sDestination, 1) or FileCopy suffice? Please help us understand your logic so we can give you a clean, working script. I point this out to you in a friendly spirit, with the comfort that our long-standing interaction on this forum has given us. Melba23 and argumentum 2 I know that I know nothing
mr-es335 Posted February 24 Author Posted February 24 (edited) ioa747, Thanks for the follow-up...appreciated! My primary objective here is to create "portable installations" of various digital audio applications. • For example, RML Labs SAC and SAW, Native Instruments Guitar Rig 5 and 3, Valhalla reverbs - the most "complicated" is Native Instruments Guitar Rig 5. Once the application is installed, I then make it so that all that is required to "install" that application is a file|folder copy. For Guitar Rig 5, I require the following: 1) I need to backup 4 files only via a "BackupFileData" script 2) I need to backup 6 complete folders via a "BackupFolderData" script Once a "backup" has been completed, I then completely uninstall Guitar Rig 5 - including any "orphaned" data. Finally, I restore Guitar Rig 5 via a "restore" script. My only "dilemma" is that I have been having to write out the entire source and destination paths. • I understand the need for the source paths, but have been unable to reduce the need to provide the entire destination path. My objective here then is simply to simplify both my backup and restore scripts. I have provided both the backup and restore scripts that I have employed since I began employing AutoIt! The backup script: Spoiler expandcollapse popup; ----------------------------------------------- #include "ExtMsgBox.au3" #include <FileConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- BackupFileFolderData() ; ----------------------------------------------- Func BackupFileFolderData() BackupFileData() BackupFolderData() EndFunc ;==>BackupFileFolderData ; ----------------------------------------------- Func BackupFileData() Local $sStartMsg = "File backup in progress..." Local $sEndMsg = "File backup has completed!" ; ----------------- Local $iStart = 5, $iEnd = 4 Local $sSrcPath[$iStart] = [$iEnd] Local $sDstPath[$iStart] = [$iEnd] ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 450) _ExtMsgBox(0, " ", " Notice!", $sStartMsg, 2) ; ----------------------------------------------- $sSrcPath[1] = "C:\Windows\System32\msvcp120.dll" $sSrcPath[2] = "C:\Windows\System32\msvcr120.dll" $sSrcPath[3] = "C:\Windows\SysWOW64\msvcp120.dll" $sSrcPath[4] = "C:\Windows\SysWOW64\msvcr120.dll" ; ----------------- $sDstPath[1] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Windows\System32\" $sDstPath[2] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Windows\System32\" $sDstPath[3] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Windows\SysWOW64\" $sDstPath[4] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Windows\SysWOW64\" ; ----------------------------------------------- For $i = 1 To $sSrcPath[0] FileMove($sSrcPath[$i], $sDstPath[$i], $FC_OVERWRITE + $FC_CREATEPATH) Next ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 450) _ExtMsgBox(0, " ", " Notice!", $sEndMsg, 2) EndFunc ;==>BackupFileData ; ----------------------------------------------- Func BackupFolderData() Local $sStartMsg = "Folder backup in progress..." Local $sEndMsg = "Folder backup has completed!" ; ----------------- Local $iStart = 7, $iEnd = 6 Local $sSrcPath[$iStart] = [$iEnd] Local $sDstPath[$iStart] = [$iEnd] ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 450) _ExtMsgBox(0, " ", " Notice!", $sStartMsg, 2) ; ----------------------------------------------- $sSrcPath[1] = "C:\Program Files\Common Files\Native Instruments" $sSrcPath[2] = "C:\Program Files\Native Instruments" $sSrcPath[3] = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Native Instruments" $sSrcPath[4] = "C:\Users\RML_User\AppData\Local\Native Instruments" $sSrcPath[5] = "C:\Users\Public\Public Desktop" $sSrcPath[6] = "E:\Text\Native Instruments" ; ----------------- $sDstPath[1] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Program Files\Common Files\Native Instruments" $sDstPath[2] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Program Files\Native Instruments" $sDstPath[3] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\ProgramData\Microsoft\Windows\Start Menu\Programs\Native Instruments" $sDstPath[4] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Users\RML_User\AppData\Local\Native Instruments" $sDstPath[5] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC\Users\Public\Public Desktop" $sDstPath[6] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataE\Text\Native Instruments" ; ----------------------------------------------- For $i = 1 To $sSrcPath[0] DirCopy($sSrcPath[$i], $sDstPath[$i], $FC_OVERWRITE) Next ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 450) _ExtMsgBox(0, " ", " Notice!", $sEndMsg, 2) EndFunc ;==>BackupFolderData ; ----------------------------------------------- ...and the restore script: Spoiler ; ----------------------------------------------- #include "ExtMsgBox.au3" #include <FileConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- RestoreFolderData() ; ----------------------------------------------- Func RestoreFolderData() Local $sStartMsg = "Restore folders in progress..." Local $sEndMsg = "Restore folders has completed!" ; ----------------- Local $iStart = 3, $iEnd = 2 Local $sSrcPath[$iStart] = [$iEnd] Local $sDstPath[$iStart] = [$iEnd] ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 450) _ExtMsgBox(0, " ", " Notice!", $sStartMsg, 2) ; ----------------------------------------------- $sSrcPath[1] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataC" $sSrcPath[2] = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceDataE" ; ----------------- $sDstPath[1] = "C:" $sDstPath[2] = "E:" ; ----------------------------------------------- For $i = 1 To $sSrcPath[0] DirCopy($sSrcPath[$i], $sDstPath[$i], $FC_OVERWRITE) Next ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 450) _ExtMsgBox(0, " ", " Notice!", $sEndMsg, 2) EndFunc ;==>RestoreFolderData ; ----------------------------------------------- As can hopefully be observed: 1) I am employing FIleMove() and DirCopy() to "backup" that data. 2) Once the data has been backed-up, I can then completely uninstall the application 3) I then restore that application via DirCopy() PS: A s can be observed, I am NOT employing any "error checking" - for the simple reason that these scripts are only being employed by me, and I know exactly what data is required for BOTH the source and destination scripts. Now, in the example above, [from the aye-eye search], I have been able to greatly simply the source and destination paths via "_FileListToArray" and|or "_FileListToArrayRec". I DO hope that the above provides a more thorough explanation of what it is that I am attempting to accomplish here. At the end of the day however, what I am really looking for is a single script that will copy BOTH specific files and folders within a single script! • The ONLY way in which I have been able to accomplish this task is via a "BackupFileFolderData" script that calls a "BackupFileData" script and a "BackupFolderData" script. Edited February 24 by mr-es335 mr-es335 Sentinel Music Studios
mr-es335 Posted February 24 Author Posted February 24 Hhhmmmm...came across this little tid-bit: [Click_Me] mr-es335 Sentinel Music Studios
ioa747 Posted February 24 Posted February 24 (edited) It’s clear now: you are doing "surgical" backups. The solution is to use a Relative Path logic. Since your destination always follows the pattern BaseDir + DriveLetter + OriginalPath, we can automate this entirely. Also, by using FileGetAttrib, the script can automatically decide whether to use FileCopy or DirCopy. You don't need two separate functions anymore! Here is the unified, simplified function: expandcollapse popupBackupRestore_Engine(True) ; True for Backup, False for Restore Func BackupRestore_Engine($bIsBackup) Local $sSrc, $sDest, $sDrive, $sRelativePath Local $sBaseBackupDir = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceData" Local $aData[] = [ _ "C:\Windows\System32\msvcp120.dll", _ "C:\Windows\System32\msvcr120.dll", _ "C:\Windows\SysWOW64\msvcp120.dll", _ "C:\Windows\SysWOW64\msvcr120.dll", _ "C:\Program Files\Common Files\Native Instruments", _ "C:\Program Files\Native Instruments", _ "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Native Instruments", _ "C:\Users\RML_User\AppData\Local\Native Instruments", _ "C:\Users\Public\Public Desktop", _ "E:\Text\Native Instruments"] For $i = 0 To UBound($aData) - 1 $sSrc = $aData[$i] ; Get the first letter eg: C or E $sDrive = StringLeft($sSrc, 1) ; Get the path without the drive letter $sRelativePath = StringTrimLeft($sSrc, 3) ; Build the final Destination Path $sDest = $sBaseBackupDir & $sDrive & "\" & $sRelativePath If $bIsBackup Then ; === Backup Logic (Src to Dest) === If Not FileExists($sSrc) Then ConsoleWrite($i & ") !! File: " & $sSrc & " NOT found" & @CRLF) ContinueLoop EndIf If StringInStr(FileGetAttrib($sSrc), "D") = 0 Then ; FileCopy($sSrc, $sDest, $FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite($i & ") FileCopy: " & $sSrc & " to " & $sDest & @CRLF) Else ; DirCopy($sSrc, $sDest, $FC_OVERWRITE) ConsoleWrite($i & ") DirCopy: " & $sSrc & " to " & $sDest & @CRLF) EndIf Else ; === Restore Logic (Swap Dest and Src) === ; DirCopy($sDest, $sSrc, $FC_OVERWRITE) ConsoleWrite($i & ") Restore: " & $sDest & " to " & $sSrc & @CRLF) EndIf Next EndFunc ;==>BackupRestore_Engine Edit: You don't need _FileListToArray for this. What you need is a Relative Path logic. Edited February 24 by ioa747 prettify mr-es335 1 I know that I know nothing
mr-es335 Posted February 24 Author Posted February 24 (edited) iao747, Been "workin' mah way thru yur samplin'..." and I must admit, rather ingenious! ConsoleWrite-ing all over the place to how you came to the result that you did! I DID come across one tiny error: ; === Restore Logic (Swap Dest and Src) === $Result3 = FileCopy($sDest, $sSrc, $FC_OVERWRITE) ;~ $Result3 = DirCopy($sDest, $sSrc, $FC_OVERWRITE) ConsoleWrite("$Result3=" & $Result3 & @CRLF& @CRLF) ConsoleWrite($i & ") Restore: " & $sDest & " to " & $sSrc & @CRLF) DIrCopy is attempting to copy files files from the path: "C:\Windows\System32" and "C:\Windows\WOW64". Employing FileCopy resolved that issue. Now, to see how to employ both. How is the following for a possible solution? ; === Restore Logic (Swap Dest and Src) === $DirCopyResult = DirCopy($sDest, $sSrc, $FC_OVERWRITE) ConsoleWrite("$DirCopyResult=" & $DirCopyResult & @CRLF) If $DirCopyResult = 0 Then $FileCopyResult = FileCopy($sDest, $sSrc, $FC_OVERWRITE) ConsoleWrite("$FileCopyResult=" & $FileCopyResult & @CRLF) EndIf Edited February 24 by mr-es335 mr-es335 Sentinel Music Studios
mr-es335 Posted February 25 Author Posted February 25 iao747, How is this?: Spoiler expandcollapse popup; ----------------------------------------------- #include "ExtMsgBox.au3" #include <FileConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- StartHere() ; ----------------------------------------------- Func StartHere() Local $sMsg = "Do you want to perform a backup or a restore?" & @CRLF Local $sResult ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 550) ; ----------------------------------------------- $sResult = _ExtMsgBox(64, "Backup|Restore|~Cancel", " Notice!", $sMsg, 0, 0, False) ; ----------------------------------------------- Switch $sResult Case 1 Backup() Case 2 Restore() Case 3 CancelMe() EndSwitch EndFunc ;==>StartHere ; ----------------------------------------------- Func CancelMe() Exit EndFunc ;==>CancelMe ; ----------------------------------------------- Func Backup() MasterBackupRestore(True) EndFunc ;==>Backup ; ----------------------------------------------- Func Restore() MasterBackupRestore(False) EndFunc ;==>Restore ; ----------------------------------------------- Func MasterBackupRestore($bIsBackup) Local $sSrc, $sDest, $sDrive, $sRelativePath Local $sBaseBackupDir = "" Local $aData[] = [ _ "", _ "", _ ""] ; ----------------------------------------------- For $i = 0 To UBound($aData) - 1 $sSrc = $aData[$i] ; Obtain the first letter [C or E] $sDrive = StringLeft($sSrc, 1) ; Obtain the path without the drive letter $sRelativePath = StringTrimLeft($sSrc, 3) ; Create the final Destination Path $sDest = $sBaseBackupDir & $sDrive & "\" & $sRelativePath ; ----------------------------------------------- If $bIsBackup Then ConsoleWrite("$bIsBackup=" & $bIsBackup & @CRLF & @CRLF) ; === Backup Logic (Src to Dest) === If Not FileExists($sSrc) Then ContinueLoop EndIf If StringInStr(FileGetAttrib($sSrc), "D") = 0 Then FileCopy($sSrc, $sDest, $FC_OVERWRITE + $FC_CREATEPATH) Else DirMove($sSrc, $sDest, $FC_OVERWRITE) EndIf Else ; === Restore Logic (Swap Dest and Src) === ConsoleWrite("$bIsBackup=" & $bIsBackup & @CRLF & @CRLF) Local $DirCopyResult = DirCopy($sDest, $sSrc, $FC_OVERWRITE) If $DirCopyResult = 0 Then Local $FileCopyResult = FileCopy($sDest, $sSrc, $FC_OVERWRITE) EndIf EndIf Next EndFunc ;==>MasterBackupRestore ; ----------------------------------------------- mr-es335 Sentinel Music Studios
ioa747 Posted February 25 Posted February 25 (edited) keep it simple Spoiler expandcollapse popup; ----------------------------------------------- #include "ExtMsgBox.au3" #include <FileConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- StartHere() ; ----------------------------------------------- Func StartHere() Local $sMsg = "Do you want to perform a backup or a restore?" & @CRLF Local $sResult ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 550) ; ----------------------------------------------- $sResult = _ExtMsgBox(64, "Backup|Restore|~Cancel", " Notice!", $sMsg, 0, 0, False) ; ----------------------------------------------- Switch $sResult Case 1 MasterBackupRestore(True) Case 2 MasterBackupRestore(False) Case 3 Exit EndSwitch EndFunc ;==>StartHere ; ----------------------------------------------- Func MasterBackupRestore($bIsBackup) Local $sSrc, $sDest, $sDrive, $sRelativePath Local $sBaseBackupDir = "" Local $aData[] = [ _ "", _ "", _ ""] ; ----------------------------------------------- Local $sH1 = ($bIsBackup ? "=== Backup Logic (Src to Dest) ===" : "=== Restore Logic (Swap Dest and Src) ===") ConsoleWrite($sH1 & @CRLF) ; ----------------------------------------------- For $i = 0 To UBound($aData) - 1 $sSrc = $aData[$i] ; Obtain the first letter [C or E] $sDrive = StringLeft($sSrc, 1) ; Obtain the path without the drive letter $sRelativePath = StringTrimLeft($sSrc, 3) ; Create the final Destination Path $sDest = $sBaseBackupDir & $sDrive & "\" & $sRelativePath ; ----------------------------------------------- Local $iCopyResult If $bIsBackup Then ; === Backup Logic (Src to Dest) === If Not FileExists($sSrc) Then ContinueLoop EndIf If StringInStr(FileGetAttrib($sSrc), "D") = 0 Then $iCopyResult = FileCopy($sSrc, $sDest, $FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite($i & ") FileCopy: " & $sSrc & " -> " & $iCopyResult & @CRLF) Else $iCopyResult = DirCopy($sSrc, $sDest, $FC_OVERWRITE) ConsoleWrite($i & ") DirCopy: " & $sSrc & " -> " & $iCopyResult & @CRLF) EndIf Else ; === Restore Logic (Swap Dest and Src) === If StringInStr(FileGetAttrib($sDest), "D") Then $iCopyResult = DirCopy($sDest, $sSrc, $FC_OVERWRITE) ConsoleWrite($i & ") Restore Folder: " & $sDest & " -> " & $iCopyResult & @CRLF) Else $iCopyResult = FileCopy($sDest, $sSrc, $FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite($i & ") Restore File: " & $sDest & " -> " & $iCopyResult & @CRLF) EndIf EndIf Next EndFunc ;==>MasterBackupRestore ; ----------------------------------------------- Edit: Attention, I saw that you changed the DirCopy($sSrc, $sDest, $FC_OVERWRITE) to DirMove($sSrc, $sDest, $FC_OVERWRITE) If you did it thinking everything is fine Edited February 25 by ioa747 I know that I know nothing
mr-es335 Posted February 25 Author Posted February 25 io9a747, The change to DirMove was for a "test". Other than that, is all "OK!"? What of my attempt at a "fix" for the restore? mr-es335 Sentinel Music Studios
ioa747 Posted February 25 Posted February 25 take a look at the script above I use the same logic If StringInStr(FileGetAttrib($sDest), "D") Then I know that I know nothing
mr-es335 Posted February 25 Author Posted February 25 Sorry...completely missed that one....! mr-es335 Sentinel Music Studios
Solution ioa747 Posted February 25 Solution Posted February 25 slightly improved Spoiler expandcollapse popup; ----------------------------------------------- #include "ExtMsgBox.au3" #include <FileConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- StartHere() ; ----------------------------------------------- Func StartHere() Local $sMsg = "Do you want to perform a backup or a restore?" & @CRLF Local $sResult ; ----------------------------------------------- _ExtMsgBoxSet(64, 4, Default, Default, 16, "Corbel Bold", 550) ; ----------------------------------------------- $sResult = _ExtMsgBox(64, "Backup|Restore|~Cancel", " Notice!", $sMsg, 0, 0, False) ; ----------------------------------------------- Switch $sResult Case 1 MasterBackupRestore(True) Case 2 MasterBackupRestore(False) Case 3 Exit EndSwitch EndFunc ;==>StartHere ; ----------------------------------------------- Func MasterBackupRestore($bIsBackup) ; True for Backup, False for Restore Local $sSrc, $sDest, $sDrive, $sRelativePath Local $sBaseBackupDir = @ScriptDir & "\SourceData" If Not FileExists($sBaseBackupDir) Then DirCreate($sBaseBackupDir) Local $aData[] = [ _ @ScriptDir & "\Extras\Editors", _ @ScriptDir & "\Extras\Prettify", _ @ScriptDir & "\Extras\_ReadMe_.txt"] ; ----------------------------------------------- Local $sH1 = ($bIsBackup ? "=== Backup Logic (Src to Dest) ===" : "=== Restore Logic (Swap Dest and Src) ===") ConsoleWrite($sH1 & @CRLF) ; ----------------------------------------------- For $i = 0 To UBound($aData) - 1 $sSrc = $aData[$i] ; Obtain the first letter [C or E] $sDrive = StringLeft($sSrc, 1) ; Obtain the path without the drive letter $sRelativePath = StringTrimLeft($sSrc, 3) ; Create the final Destination Path $sDest = $sBaseBackupDir & "\" & $sDrive & "\" & $sRelativePath ; ----------------------------------------------- Local $iCopyResult If $bIsBackup Then ; === Backup Logic (Src to Dest) === If Not FileExists($sSrc) Then ConsoleWrite($i & ") !! Skipping File: " & $sSrc & " NOT found" & @CRLF) ContinueLoop EndIf If StringInStr(FileGetAttrib($sSrc), "D") = 0 Then $iCopyResult = FileCopy($sSrc, $sDest, $FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite($i & ") FileCopy: " & $sSrc & " -> " & $iCopyResult & @CRLF) Else $iCopyResult = DirCopy($sSrc, $sDest, $FC_OVERWRITE) ConsoleWrite($i & ") DirCopy: " & $sSrc & " -> " & $iCopyResult & @CRLF) EndIf Else ; === Restore Logic (Swap Dest and Src) === If StringInStr(FileGetAttrib($sDest), "D") Then $iCopyResult = DirCopy($sDest, $sSrc, $FC_OVERWRITE) ConsoleWrite($i & ") Restore Folder: " & $sDest & " -> " & $iCopyResult & @CRLF) Else $iCopyResult = FileCopy($sDest, $sSrc, $FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite($i & ") Restore File: " & $sDest & " -> " & $iCopyResult & @CRLF) EndIf EndIf Next EndFunc ;==>MasterBackupRestore ; ----------------------------------------------- mr-es335 1 I know that I know nothing
mr-es335 Posted February 25 Author Posted February 25 (edited) ioa747, Thanks for this...still getting my head around it!!! I am not sure how to test the following: If StringInStr(FileGetAttrib($sDest), "D") Then Regardless, I am assuming that the above text is stating: 1) If the string within the destination path IS designated as a directory then select DirCopy(). 2) 1) If the string within the destination path IS NOT designated as a directory - thus a file, then select FileCopy(). Would this assumption be correct? From "aye-eee": $sDest = "E:\Desktop\ThemD\Important_Data\Testing\Current\Src\Us" If StringInStr(FileGetAttrib($sDest), "D") Then ; The path is a directory MsgBox(0, "Info", "The destination is a directory.") Else ; The path is not a directory MsgBox(0, "Info", "The destination is not a directory.") EndIf $sDest = "E:\Desktop\ThemD\Important_Data\Testing\Current\Src\Us" If StringInStr(FileGetAttrib($sDest), "D") Then ; The path is a directory MsgBox(0, "Info", "The destination is a directory.") Else ; The path is not a directory MsgBox(0, "Info", "The destination is not a directory.") EndIf Edited February 26 by mr-es335 mr-es335 Sentinel Music Studios
ioa747 Posted February 26 Posted February 26 (edited) Why don't you do a real test with the data you needed? to see if it works? and how. Local $sBaseBackupDir = "D:\App_Install\Digital_Audio\2_GR5\Data\SourceData" Local $aData[] = [ _ "C:\Windows\System32\msvcp120.dll", _ "C:\Windows\System32\msvcr120.dll", _ "C:\Windows\SysWOW64\msvcp120.dll", _ "C:\Windows\SysWOW64\msvcr120.dll", _ "C:\Program Files\Common Files\Native Instruments", _ "C:\Program Files\Native Instruments", _ "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Native Instruments", _ "C:\Users\RML_User\AppData\Local\Native Instruments", _ "C:\Users\Public\Public Desktop", _ "E:\Text\Native Instruments"] Edited February 26 by ioa747 mr-es335 1 I know that I know nothing
mr-es335 Posted February 27 Author Posted February 27 ioa747, Will do,,,and have done! By-the-way...thanks for this little "tid-bit": Local $aData[] = [ _ "path", _ "path"] My surgical brain really prefers consistency! ioa747 1 mr-es335 Sentinel Music Studios
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