Jump to content

Obtain Folder Name


Recommended Posts

Good day,
I hope that the day finds you well!

  1. I employ a specific "root" folder - in this case the folder name is "Installations".
  2. Within this folder, I have created a "Master" folder called "Install_" that also contains various sub-folders.
  3. This "Master" folder is "copied-and-then-renamed" - say to "Install_1a".
  4. I need to be able to store backup data specific to that "copied-and-then-renamed" folder.
  5. The "source" data locations are always the same, but where the name of destination folder is altered - as noted above.

My question is, "Is there a means of being able to 'read' a specific destination folder location, and then to 'store' that information in a variable to employ in a copy/backup script?"

Here is a sampling of what I have able to deploy. However, I would prefer not to have employ an "Input" box...

;-----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
;-----------------------------------------------
Opt("MustDeclareVars", 1)
;------------------------------------------------
Local $MyPath = ''
;------------------
Local $sSrcCFPath = "C:\Program Files\Common Files\Native Instruments"
;------------------
Local $sSrcPFFolderPath = "C:\Program Files\Native Instruments"
;------------------
Local $sSrcADFolderPath = "C:\Users\Dell\AppData\Local\Native Instruments"
;------------------
Local $sSrcTXTFolderPath = "E:\Text\Native Instruments"
;------------------------------------------------
_Create_Dir()
;------------------------------------------------
Func _Create_Dir()
    ; Obtain path from user input
    $MyPath = InputBox("NOTICE!", "Enter Destination path...", "", "", 200, 50)
    ;------------------
    SplashTextOn("NOTICE!!", "Copying Guitar Rig 5 source data...", 350, 50, -1, -1)
    Sleep(1000)
    ;------------------
    DirCopy($sSrcCFPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Program Files\Common Files\Native Instruments", $FC_OVERWRITE)
    DirCopy($sSrcPFFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Program Files\Native Instruments" , $FC_OVERWRITE)
    DirCopy($sSrcADFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Users\Dell\AppData\Local\Native Instruments", $FC_OVERWRITE)
    DirCopy($sSrcTXTFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_E\Text\Native Instruments", $FC_OVERWRITE)
    ;------------------
    SplashTextOn("NOTICE!!", "Copying Guitar Rig 5 data source completed...", 350, 50, -1, -1)
    Sleep(1000)
EndFunc   ;==>_Create_Dir
;------------------------------------------------

Thank you for your time and attention to the above. Both are very much appreciated!

Link to comment
Share on other sites

If it were me, I would use the date/time as the variable. It always changes and you know exactly when it was backed up. If you want to use a folder path like "Install_1a" and increment it to "Install_1b", to "Install_1z", then "Install_2a" to "Install_2z", that can be done with reading/writing an ini file, a double loop, and some fancy StringSplit and Chr(num) incremental stuff. 

Here's the date idea I mentioned (file/folder names cannot use slashes or colons, so I only used dashes and underscores):

;-----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
;-----------------------------------------------
Opt("MustDeclareVars", 1)
;------------------------------------------------
;Local $MyPath = ''   ; Not necessary because local can be decalred in the function
;------------------
Local $sSrcCFPath = "C:\Program Files\Common Files\Native Instruments"
;------------------
Local $sSrcPFFolderPath = "C:\Program Files\Native Instruments"
;------------------
Local $sSrcADFolderPath = "C:\Users\Dell\AppData\Local\Native Instruments"
;------------------
Local $sSrcTXTFolderPath = "E:\Text\Native Instruments"
;------------------------------------------------
_Create_Dir()
;------------------------------------------------
Func _Create_Dir()
    Local $MyPath = @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN
;~  MsgBox(0, "", $MyPath)
    ;------------------
    SplashTextOn("NOTICE!!", "Copying Guitar Rig 5 source data...", 350, 50, -1, -1)
    Sleep(1000)
    ;------------------
;~     DirCopy($sSrcCFPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Program Files\Common Files\Native Instruments", $FC_OVERWRITE)
;~     DirCopy($sSrcPFFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Program Files\Native Instruments" , $FC_OVERWRITE)
;~     DirCopy($sSrcADFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Users\Dell\AppData\Local\Native Instruments", $FC_OVERWRITE)
;~     DirCopy($sSrcTXTFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_E\Text\Native Instruments", $FC_OVERWRITE)
    ;------------------
    SplashTextOn("NOTICE!!", "Copying Guitar Rig 5 data source completed...", 350, 50, -1, -1)
    Sleep(1000)
EndFunc   ;==>_Create_Dir
;------------------------------------------------

 

Link to comment
Share on other sites

I was wrong about needing a double loop. I made something that I think will work for you, but I did not test the final code because I don't have your folders on my computer. Here is an example script that simply shows an install number incremented with numbers and letters (keep pressing the Backup Guitar Rig button to see the variable changes):

#include <ButtonConstants.au3>
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $Form1 = GUICreate("Guitar Rig Backup", 266, 111)
Global $Button1 = GUICtrlCreateButton("Backup Guitar Rig", 64, 24, 131, 49, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $sInstallVersion = IniRead("GuitarRigVersion.ini", "Version", "Value", "Install_1a")
            Local $aString = StringSplit($sInstallVersion, "")

            Local $sLetter = $aString[$aString[0]] ; this chooses the last character of the string
            Local $iNum = $aString[$aString[0] - 1] ; this chooses the second to the last character of the string

            If Asc($sLetter) < 122 Then ; 97 to 122 are ascii characters a-z
                $sLetter = Chr(Asc($sLetter) + 1)
            ElseIf Asc($sLetter) = 122 Then ; if it goes beyond the letter z, increment number and reset to letter a
                $iNum = Chr(Asc($iNum) + 1)
                $sLetter = Chr(97)
            EndIf

            IniWrite("GuitarRigVersion.ini", "Version", "Value", "Install_" & $iNum & $sLetter)
            Sleep(100) ; added this because I have had fast CPUs run faster than the hard drive can write this data
            Local $sInstallVersion = IniRead("GuitarRigVersion.ini", "Version", "Value", "Install_1a")
            MsgBox(0, "", $sInstallVersion)
    EndSwitch
WEnd

And here it is integrated with your code (you may have to debug it):

#include <ButtonConstants.au3>
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)
Global $sInstallVersion
Local $sSrcCFPath = "C:\Program Files\Common Files\Native Instruments"
Local $sSrcPFFolderPath = "C:\Program Files\Native Instruments"
Local $sSrcADFolderPath = "C:\Users\Dell\AppData\Local\Native Instruments"
Local $sSrcTXTFolderPath = "E:\Text\Native Instruments"

Global $Form1 = GUICreate("Guitar Rig Backup", 266, 111)
Global $Button1 = GUICtrlCreateButton("Backup Guitar Rig", 64, 24, 131, 49, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $sInstallVersion = IniRead("GuitarRigVersion.ini", "Version", "Value", "Install_1a")
            Local $aString = StringSplit($sInstallVersion, "")

            Local $sLetter = $aString[$aString[0]] ; this chooses the last character of the string
            Local $iNum = $aString[$aString[0] - 1] ; this chooses the second to the last character of the string

            If Asc($sLetter) < 122 Then
                $sLetter = Chr(Asc($sLetter) + 1)
            ElseIf Asc($sLetter) = 122 Then
                $iNum = Chr(Asc($iNum) + 1)
                $sLetter = Chr(97)
            EndIf

            IniWrite("GuitarRigVersion.ini", "Version", "Value", "Install_" & $iNum & $sLetter)
            Sleep(100) ; added this because I have had fast CPUs run faster than the hard drive can write this data
            Local $sInstallVersion = IniRead("GuitarRigVersion.ini", "Version", "Value", "Install_1a")
            _Create_Dir($sInstallVersion)
    EndSwitch
WEnd

;------------------------------------------------
Func _Create_Dir($MyPath)
    SplashTextOn("NOTICE!!", "Copying Guitar Rig 5 source data...", 350, 50, -1, -1)
    Sleep(1000)
    ;------------------
    DirCopy($sSrcCFPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Program Files\Common Files\Native Instruments", $FC_OVERWRITE)
    DirCopy($sSrcPFFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Program Files\Native Instruments" , $FC_OVERWRITE)
    DirCopy($sSrcADFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_C\Users\Dell\AppData\Local\Native Instruments", $FC_OVERWRITE)
    DirCopy($sSrcTXTFolderPath, "I:\Guitar_Rig\Installations\" & $MyPath & "\Data\Source_Data_E\Text\Native Instruments", $FC_OVERWRITE)
;~     ;------------------
    SplashTextOn("NOTICE!!", "Copying Guitar Rig 5 data source completed...", 350, 50, -1, -1)
    Sleep(1000)
EndFunc   ;==>_Create_Dir

 

Edited by abberration
Link to comment
Share on other sites

9 hours ago, mr-es335 said:
SplashTextOn("NOTICE!!", "Copying Guitar Rig 5 source data..."

Here I see only 4

 

9 hours ago, mr-es335 said:

My question is, "Is there a means of being able to 'read' a specific destination folder location, and then to 'store' that information in a variable to employ in a copy/backup script?"

If I understood your question correctly.
You can pass this information as command line parameters when you call your script

 

 

I know that I know nothing

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...