Jump to content

Recommended Posts

Posted (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
; -----------------------------------------------
#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
; -----------------------------------------------
#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 by mr-es335
Posted

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

 

Posted (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 by mr-es335
Posted

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.

I know that I know nothing

Posted (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
; -----------------------------------------------
#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 by mr-es335
Posted (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:

BackupRestore_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 by ioa747
prettify

I know that I know nothing

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
×
×
  • Create New...