Jump to content

StringRegExp Assistance


Recommended Posts

Good day,

I would really appreciate some assistance with regards to a portion of a script that was provided for me, and of which, I have NO IDEA what is going on or how to "ConsoleWrite" this protion of script?

Any assistance|clarification in this matter would be greatly appreciated!  Here is the script:

; -----------------------------------------------
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_BrowseForFolder()
; -----------------------------------------------
Func _BrowseForFolder()
    While 1
        Local $SetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "F:\Audio")
        ; -----------------------------------------------
        Local $_aType = StringSplit($SetName, "\")
        If $_aType[0] = 4 Then
            If $_aType[2] = "Audio" And StringRegExp($_aType[3], "Type_[1-4]") Then
                Local $_sTypeFolder = $_aType[1] & "\" & $_aType[2] & "\" & $_aType[3]
                Local $_sSetName = $_aType[4]
                _MoveSourceAudioData($_sTypeFolder, $_sSetName)
                ExitLoop
            EndIf
        EndIf
        ; -----------------------------------------------
        MsgBox($MB_TOPMOST, "Notice!", "Invalid [F:\Audio\Type_#\Set_Name] folder selected...")
    WEnd
EndFunc   ;==>_BrowseForFolder
; -----------------------------------------------
Func _MoveSourceAudioData($_sTypeFolder, $_sSetName)
    MsgBox($MB_TOPMOST, "", "Inside of _MoveSourceAudioData...with: " & @CRLF & $_sTypeFolder & "\" & $_sSetName & "\wav")
EndFunc   ;==>_FunctionType_1
; -----------------------------------------------

...in particular, this line:

If $_aType[2] = "Audio" And StringRegExp($_aType[3], "Type_[1-4]") Then

The following paths are what I am deploying for this example:

F:\Audio [The default "root" path]

F:\Audio\Type_1\AllMe

F:\Audio\Type_2\AllMe
F:\Audio\Type_2\A\AllMe

F:\Audio\Type_3\AllMe

F:\Audio\Type_4\AllMe

 

Link to comment
Share on other sites

ioa747,

Firstly, I am simply attempting to ascertain what is going on i the above script...so that I may learn from it...again, especially with regards to "StringRegExp($_aType[3], "Type_[1-4]")"...

Secondly, I updated this line:

If $_aType[2] = "Audio" And StringRegExp($_aType[3], "Type_[1-4]") Then

...to this...

If $_aType[3] = $_aType[3] And StringRegExp($_aType[3], "Type_[1-4]") Then

...as "Audio" has already been predetermined...

I also updated this...

; -----------------------------------------------
Func _MoveSourceAudioData($_sTypeFolder, $_sSetName)
    MsgBox($MB_TOPMOST, "", "Inside of _MoveSourceAudioData...with: " & @CRLF & $_sTypeFolder & "\" & $_sSetName & "\wav")
EndFunc   ;==>_FunctionType_1
; -----------------------------------------------

...to this...

Func _MoveSourceAudioData($_sTypeFolder, $_sSetName)
    ConsoleWrite($_sTypeFolder & @CRLF)
    ConsoleWrite($_sSetName & @CRLF)
    MsgBox($MB_TOPMOST, "", "Inside of _MoveSourceAudioData...with: " & @CRLF & $_sTypeFolder & "\" & $_sSetName & "\wav")
EndFunc   ;==>_MoveSourceAudioData
; -----------------------------------------------

 

Edited by mr-es335
Link to comment
Share on other sites

If $_aType[2] = "Audio" And StringRegExp($_aType[3], "Type_[1-4]") Then
What does the line mean?

if we have the path: F:\Audio\Type_2\AllMe

then is
$_aType[0] = 4
$_aType[1] = F:
$_aType[2] = Audio
$_aType[3] = Type_2
$_aType[4] = AllMe

If $_aType[2] = "Audio"

And $_aType[3] = Type_ and a number from 1 to 4  Then

 

Edit:
I also updated this...  ...to this...
If $_aType[3] = $_aType[3] And StringRegExp($_aType[3], "Type_[1-4]") Then
What does the line mean?

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

; -----------------------------------------------
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_BrowseForFolder()
; -----------------------------------------------
Func _BrowseForFolder()
    While 1
        Local $SetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "F:\Audio")
        ; -----------------------------------------------
        Local $_aType = StringSplit($SetName, "\")

        If $_aType[0] = 4 Then
            ConsoleWrite("[0]=" & $_aType[0] & @CRLF)
            ConsoleWrite("[1]=" & $_aType[1] & @CRLF)
            ConsoleWrite("[2]=" & $_aType[2] & @CRLF)
            ConsoleWrite("[3]=" & $_aType[3] & @CRLF)
            ConsoleWrite("[4]=" & $_aType[4] & @CRLF)
            If $_aType[2] = "Audio" And StringRegExp($_aType[3], "Type_[1-4]") Then
                Local $_sTypeFolder = $_aType[1] & "\" & $_aType[2] & "\" & $_aType[3] & "\" & $_aType[4]
                _MoveSourceAudioData($_sTypeFolder)
                ExitLoop
            EndIf
        EndIf
        ; -----------------------------------------------
        MsgBox($MB_TOPMOST, "Notice!", "Invalid [F:\Audio\Type_#\Set_Name] folder selected...")
    WEnd
EndFunc   ;==>_BrowseForFolder
; -----------------------------------------------
Func _MoveSourceAudioData($sFolderPath)
    ConsoleWrite("Inside of _MoveSourceAudioData...with: " & $sFolderPath & "\wav" & @CRLF)
EndFunc   ;==>_MoveSourceAudioData
; -----------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

ioa7477,

Thanks...will "dissect" the above...

I forgot that you had also provided this little snippet...

; -----------------------------------------------
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_BrowseForFolder()
; -----------------------------------------------
Func _BrowseForFolder()
    While 1
        Local $_sSetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "F:\Audio\")
        Local $iFileExists = FileExists($_sSetName & "\wav")
        ; -----------------------------------------------
        If StringRegExp($_sSetName & "\", "\\Type_[1-4]\\") Then
            ; -------------
            If $iFileExists Then
                _MoveSourceAudioData($_sSetName)
                ExitLoop
            EndIf
        Else
            MsgBox($MB_TOPMOST, "NOTICE!", "You must to select a valid Type_#\Set_Name folder...")
        EndIf
    WEnd
EndFunc   ;==>_BrowseForFolder
; -----------------------------------------------
Func _MoveSourceAudioData($_sSetName)
    ConsoleWrite($_sSetName & @CRLF)
    MsgBox($MB_TOPMOST, "", "Inside of _MoveSourceAudioData...with: " & "\" & $_sSetName & "\wav")
EndFunc   ;==>_MoveSourceAudioData
; -----------------------------------------------

 

Link to comment
Share on other sites

$test = "Type_1"
ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]") & @CRLF)

$test = "Type_10"
ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]") & @CRLF)

$test = "Type_5"
ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]") & @CRLF)

$test = "Type_10"
ConsoleWrite("--> " & StringRegExp($test, "Type_[1-4]$") & @CRLF)

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

ioa747,

Such examples are "extremely helpful" and should be made available in the HelpFile [...I have developed my own HelpFile of such snippets...]

Also, I want to extend a "Thank You!" to you, for assisting me in getting around the "Global Variable" employment debacle.

The above "_BrowseForFolder" function consists of four supporting Functions...all of which now employ local variables!

PS: I have now marked the following as the solution...[FileSelectFolder Issues] ...the only modifications were with regards to the removal of all "Global Variables"...

Here is the "Final Solution" then...

; -----------------------------------------------
; https://www.autoitscript.com/forum/topic/212495-fileselectfolder-issues/?do=findComment&comment=1538829
; -----------------------------------------------
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_BrowseForFolder()
; -----------------------------------------------
Func _BrowseForFolder()
    While 1
        Local $_sSetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "F:\Audio\")  ; "F:\Audio\"
        ConsoleWrite("$_sSetName=" & $_sSetName & @CRLF)
        ; -----------------------------------------------
        If @error Then
            MsgBox($MB_TOPMOST, "", "No valid Type_#\Set_Name folder was selected." & @CRLF & "Please select a valid Type_#\Set_Name folder")
            ContinueLoop
        EndIf
        ; -----------------------------------------------
        If StringRegExp($_sSetName & "\", "\\Type_[1-2]\\") Then
            ConsoleWrite("$_aGetType=" & $_sSetName & @CRLF)
            _MoveSourceAudioData($_sSetName)
            ExitLoop
        Else
            MsgBox($MB_TOPMOST, "NOTICE!", "You must to select a valid Type_#\Set_Name folder...")
        EndIf
    WEnd
EndFunc   ;==>_BrowseForFolder
; -----------------------------------------------
Func _MoveSourceAudioData($_sSetName)
    MsgBox($MB_TOPMOST, "NOTICE!", "Made it to _MoveSourceAudioData...with..." & @CRLF & " ..." & $_sSetName & "...as the \wav path!")
EndFunc   ;==>_MoveSourceAudioData
; -----------------------------------------------

 

Edited by mr-es335
Errors in script example
Link to comment
Share on other sites

Func _MoveSourceAudioData($sFolderPath)
    If FileExists($sFolderPath & "\wav") Then
         MsgBox($MB_TOPMOST, "NOTICE!", "Made it to _MoveSourceAudioData...with..." & @CRLF & " ..." & $sFolderPath & "...as the \wav path!")
    Else
         MsgBox($MB_TOPMOST, "NOTICE!", "... the \wav folder is missing in" & @CRLF & $sFolderPath)
    EndIf
EndFunc   ;==>_MoveSourceAudioData

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

6 minutes ago, ioa747 said:
Func _MoveSourceAudioData($_sSetName) ; Corrected variable
    If FileExists($g_SetName & "\wav") Then
         MsgBox($MB_TOPMOST, "NOTICE!", "Made it to _MoveSourceAudioData...with..." & @CRLF & " ..." & $_sSetName & "...as the \wav path!") ; Corrected variable
    Else
         MsgBox($MB_TOPMOST, "NOTICE!", "... the \wav path! is missing in" & @CRLF & $_sSetName) ; Corrected variable
    EndIf
EndFunc   ;==>_MoveSourceAudioData

 

 

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...