mr-es335 Posted November 29 Share Posted November 29 (edited) Good day, In a similar manner as that of a previous posting entitled, "FileSelectFolder Issues", I am having a similar issue here...though possibly...in reverse!? Here is the script: expandcollapse popup; ----------------------------------------------- #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $g_SetName = "" ; ----------------------------------------------- _EnterSetName() _DoesFolderExist() ; ----------------------------------------------- Func _EnterSetName() $g_SetName = InputBox("Notice!", "Enter the Type_# Set_Name...", "", " M", 200, 130) ConsoleWrite("1st: $g_SetName= " & $g_SetName & @CRLF) ; ----------------- If @error Then MsgBox($MB_ICONWARNING, "Notice!", "The operation was cancelled. Exiting!") Exit Else _DoesFolderExist() EndIf EndFunc ;==>_EnterSetName ; ----------------------------------------------- Func _DoesFolderExist() Local $_DoesFolderExist = FileExists($g_SetName) Local $_sTypeFolder = StringMid($g_SetName, 10, 6) Local $_sSubFolder = StringMid($g_SetName, 17) ; ----------------------------------------------- If $_DoesFolderExist Then ; This will never occur, thus the sole purpose of _EnterSetName() ;MsgBox($MB_TOPMOST, "Success!", "The [" & $_sTypeFolder & "] subfolder [" & $_sSubFolder & "] already exists!") Else _CreateFolder() EndIf EndFunc ;==>_DoesFolderExist ; ----------------------------------------------- Func _CreateFolder() MsgBox($MB_TOPMOST, "NOTICE!", "Made it to _CreateFolder!") EndFunc ;==>_CreateFolder ; ----------------------------------------------- The issue: As with the FileSelectFolder Issues, the path must always consist of the following: F:\Audio\TypeName\SetName. However, I found that it IS possible, for me to enter F:\Audio\TypeName - which is an error, and yet the script continues. The very same anomaly occurs if I happen to enter: F:\Audio\TypeName\SetName\wav - which is also an error! As can be observed, after the path has been entered, the _DoesFolderExist function is called...and I would assume that it would be within this function that all of the necessary error trapping would occur?! Thus, I require the "ways-and-means" of being able to trap these errors before continuing on with the _CreateFolder() function. Any assistance in this matter would be greatly appreciated! UPDATE!!! It is not so much that the SetName folder exists, but rather, that the path is correct!! I do hope that this makes sense? Edited November 29 by mr-es335 Added Update!! mr-es335 Sentinel Music Studios Link to comment Share on other sites More sharing options...
ad777 Posted November 29 Share Posted November 29 hello mr-es335; i did read your topic and i did understand little bit so what you did say that you want to: Thus, I require the "ways-and-means" of being able to trap these errors before continuing on with the _CreateFolder() function. here is my solution for you: Func _DoesFolderExist() Local $_DoesFolderExist = FileExists($g_SetName) Local $_sTypeFolder = StringMid($g_SetName, 10, 6) Local $_sSubFolder = StringMid($g_SetName, 17) ; ----------------------------------------------- If $_DoesFolderExist Then ; This will never occur, thus the sole purpose of _EnterSetName() ;MsgBox($MB_TOPMOST, "Success!", "The [" & $_sTypeFolder & "] subfolder [" & $_sSubFolder & "] already exists!") Else _beforeProc() _CreateFolder() EndIf EndFunc ;==>_DoesFolderExist ; ----------------------------------------------- Func _beforeProc() ;type here your script EndFunc iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
mr-es335 Posted November 29 Author Share Posted November 29 ad777, I gather that what you are inferring to here, is that "_beforeProc()" is where the error trapping would occur? Correct? mr-es335 Sentinel Music Studios Link to comment Share on other sites More sharing options...
ad777 Posted November 29 Share Posted November 29 9 minutes ago, mr-es335 said: ad777, I gather that what you are inferring to here, is that "_beforeProc()" is where the error trapping would occur? Correct? yes correct iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
ioa747 Posted November 30 Share Posted November 30 (edited) expandcollapse popup; ----------------------------------------------- #include <MsgBoxConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $g_SetName = "" ; e.g. F:\Audio\Type_1\[Set_New_Name] ; ----------------------------------------------- _EnterSetName() _DoesFolderExist() ; ----------------------------------------------- Func _EnterSetName() Local $hGuiEnterName = GUICreate("Notice!", 206, 120, -1, -1, -1, $WS_EX_TOOLWINDOW) GUICtrlCreateLabel("Enter the Type_# and Set_Name...", 15, 10, 174, 17, $SS_CENTER) Local $ButtonCancel = GUICtrlCreateButton("cancel", 115, 85, 75, 25) Local $ComboType = GUICtrlCreateCombo("Type_1", 15, 30, 176, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Type_2") Local $sNotion = "[Set_New_Name]" Local $InputSetName = GUICtrlCreateInput($sNotion, 15, 55, 176, 21, $ES_CENTER) Local $ButtonOk = GUICtrlCreateButton("ok", 15, 85, 75, 25) GUISetState(@SW_SHOW) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $ButtonCancel ExitLoop Case $ButtonOk Local $sNewName = GUICtrlRead($InputSetName) ConsoleWrite("$sNewName=" & $sNewName & @CRLF) If StringLen($sNewName) < 1 Or $sNewName = $sNotion Then MsgBox($MB_ICONWARNING, "Notice!", "Please enter the correct name!" & @CRLF & "or press cancel, to cancel") Else $g_SetName = "F:\Audio\" & GUICtrlRead($ComboType) & "\" & $sNewName GUIDelete($hGuiEnterName) Return EndIf EndSwitch WEnd MsgBox($MB_ICONWARNING, "Notice!", "The operation was cancelled. Exiting!") Exit EndFunc ;==>_EnterSetName ; ----------------------------------------------- Func _EnterSetName000() $g_SetName = InputBox("Notice!", "Enter the Type_# Set_Name...", "", " M", 200, 130) ConsoleWrite("1st: $g_SetName= " & $g_SetName & @CRLF) ; ----------------- If @error Then MsgBox($MB_ICONWARNING, "Notice!", "The operation was cancelled. Exiting!") Exit Else _DoesFolderExist() EndIf EndFunc ;==>_EnterSetName000 ; ----------------------------------------------- Func _DoesFolderExist() Local $_DoesFolderExist = FileExists($g_SetName) Local $_sTypeFolder = StringMid($g_SetName, 10, 6) Local $_sSubFolder = StringMid($g_SetName, 17) ConsoleWrite("$g_SetName=" & $g_SetName & @CRLF) ConsoleWrite("$_DoesFolderExist=" & $_DoesFolderExist & @CRLF) ConsoleWrite("$_sTypeFolder=" & $_sTypeFolder & @CRLF) ConsoleWrite("$_sSubFolder=" & $_sSubFolder & @CRLF) ; ----------------------------------------------- If $_DoesFolderExist Then ; This will never occur, thus the sole purpose of _EnterSetName() ;MsgBox($MB_TOPMOST, "Success!", "The [" & $_sTypeFolder & "] subfolder [" & $_sSubFolder & "] already exists!") Else _CreateFolder() EndIf EndFunc ;==>_DoesFolderExist ; ----------------------------------------------- Func _CreateFolder() MsgBox($MB_TOPMOST, "NOTICE!", "Made it to _CreateFolder!") EndFunc ;==>_CreateFolder ; ----------------------------------------------- Edited November 30 by ioa747 add GUIDelete($hGuiEnterName) I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted November 30 Share Posted November 30 (edited) I don't know if you needed the other functions for anything else during the course, but for this round they can be omitted, to simplify expandcollapse popup; ----------------------------------------------- #include <MsgBoxConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $g_SetName = "" ; e.g. F:\Audio\Type_1\[Set_New_Name] ; ----------------------------------------------- _EnterSetName() ; ----------------------------------------------- Func _EnterSetName() Local $hGuiEnterName = GUICreate("Notice!", 206, 120, -1, -1, -1, $WS_EX_TOOLWINDOW) GUICtrlCreateLabel("Enter the Type_# and Set_Name...", 15, 10, 174, 17, $SS_CENTER) Local $ButtonCancel = GUICtrlCreateButton("cancel", 115, 85, 75, 25) Local $ComboType = GUICtrlCreateCombo("Type_1", 15, 30, 176, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Type_2") Local $sNotion = "[Set_New_Name]" Local $InputSetName = GUICtrlCreateInput($sNotion, 15, 55, 176, 21, $ES_CENTER) Local $ButtonOk = GUICtrlCreateButton("ok", 15, 85, 75, 25) GUISetState(@SW_SHOW) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $ButtonCancel ExitLoop Case $ButtonOk Local $sNewName = GUICtrlRead($InputSetName) ConsoleWrite("$sNewName=" & $sNewName & @CRLF) ; Remove illegal characters from $sNewName $sNewName = StringRegExpReplace($sNewName, '[\/:*?"<>|]', '') If StringLen($sNewName) < 1 Or $sNewName = $sNotion Then MsgBox($MB_ICONWARNING, "Notice!", "Please enter the correct name!" & @CRLF & "or press cancel, to cancel") Else $g_SetName = "F:\Audio\" & GUICtrlRead($ComboType) & "\" & $sNewName ConsoleWrite("$g_SetName=" & $g_SetName & @CRLF) ; Create the directory DirCreate($g_SetName) ShellExecute($g_SetName) GUIDelete($hGuiEnterName) Return EndIf EndSwitch WEnd MsgBox($MB_ICONWARNING, "Notice!", "The operation was cancelled. Exiting!") Exit EndFunc ;==>_EnterSetName ; ----------------------------------------------- Edited November 30 by ioa747 add $sNewName = StringRegExpReplace($sNewName, '[\/:*?"<>|]', '') mr-es335 1 I know that I know nothing Link to comment Share on other sites More sharing options...
mr-es335 Posted November 30 Author Share Posted November 30 (edited) ioa747, WOW...again...! It would appear, that your script has negated both the _DoesFolderExist() and the _CreateFolder() functions? Would this be a correct assertion? Just for curiosity..."What would be incorrect with the following script?" ; ------------------------------------------------------ #include <MsgBoxConstants.au3> ; ------------------------------------------------------ ; Attempt #4 _CheckPath() ; ------------------------------------------------------ Func _CheckPath() ; Uncomment one of these lines for testing purposes... ;Local $CopyMe = ClipPut("F:\Audio\Type_1\Test") ;Local $CopyMe = ClipPut("F:\Audio\Type_1\Test\wav") ; ------------------------------------------------------ Local $PathName = InputBox("Notice!", "Enter the Type_# Set_Name...", "", " M", 200, 130) ; ----------------- Local $One = StringMid($PathName, 1, 9) Local $Two = StringMid($PathName, 10, 7) Local $Three = StringMid($PathName, 17, 4) Local $Four = StringMid($PathName, 21, 4) ; ----------------- Local $CorrectPath = $One & $Two & $Three Local $IncorrectPath = $One & $Two & $Three & $Four ;MsgBox(0, "", "Correct path is: " & $CorrectPath) ;MsgBox(0, "", "Incorrect path is: " & $IncorrectPath) ; ------------------------------------------------------ Local $Result = StringCompare($CorrectPath, $IncorrectPath) ; ------------------------------------------------------ If $Result = 0 Then MsgBox(0, "", "Great!!") Else MsgBox(0, "", "Not Great!!") EndIf EndFunc ;==>_CheckPath ; ------------------------------------------------------ Edited November 30 by mr-es335 mr-es335 Sentinel Music Studios Link to comment Share on other sites More sharing options...
ioa747 Posted November 30 Share Posted November 30 (edited) 2 hours ago, mr-es335 said: It would appear, that your script has negated both the _DoesFolderExist() and the _CreateFolder() functions? Would this be a correct assertion? I wouldn't say it negates but it merges. 2 hours ago, mr-es335 said: Just for curiosity..."What would be incorrect with the following script?" I can't understand his logic. What does he want to do? try giving something simple like "hello", or "F:\Audio\Type_1\Test45" what do you expect? Edited November 30 by ioa747 add Test45 I know that I know nothing Link to comment Share on other sites More sharing options...
AndrewG Posted November 30 Share Posted November 30 @mr-es335 Any reason why you do not want to give the user of your program the benefit of being intelligent enough to choose correctly, and there by allowing the user of your program the freedom to choose the folder and file locations? Use filters in the dialogs to limit choices. How about verifying the files wanted? The easiest way for you is by file extension. The harder way for you is checking inside the file header, and even harder for you would be the data chunk - I'm not going there. I think you are trying to over engineer the problem you are trying to solve. If the edl(Edit decision list) file is just a text document that is going to loaded into Saw, let Saw tell you if the files are invalid. People do learn... come on. Link to comment Share on other sites More sharing options...
mr-es335 Posted December 1 Author Share Posted December 1 Why NOT! • Link For personal needs-and-requirements, there is "absolutely nothing wrong with employing such a practice!!" Thus of the author of the above is basing facts purely on speculation, then the author may simply need "to take a pill" and call the doctor back in the morning! Such statements as: "Hard-coding file paths also makes it extremely difficult for other people (including your future self) to use your code." • He is actually quoting Hezekiah, Chapter 12, verse 8, which states, "Thou shalt NOT code hard paths!" Ludicrous! mr-es335 Sentinel Music Studios Link to comment Share on other sites More sharing options...
mr-es335 Posted Thursday at 03:53 AM Author Share Posted Thursday at 03:53 AM (edited) Good day, Well, I do believe that I have solved the dilemma that has been plaguing me of the past few weeks. In discussing this matter out-loud with my C++ Son, I came to the realization what I required was a specific "delimiter". "And what is that delimiter you say?" Well, none other that our old friend the "backslash"!! Based on this realisation, I came up with the following "potential" [...please observe the word...] solution: ; ----------------------------------------------- #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- _EnterSetName() ; ----------------------------------------------- Func _EnterSetName() Local $_InputPath = InputBox("Notice!", "Enter the complete path...", "", " M", 200, 130) Local $_CompletePath = StringSplit($_InputPath, "\") ; ----------------------------------------------- If $_CompletePath[0] <= 3 Or $_CompletePath[0] >= 5 Then MsgBox($MB_SYSTEMMODAL, "Error!", "Incorrect path name!") _EnterSetName() Else MsgBox($MB_SYSTEMMODAL, "Success!", "Path name is correct!") EndIf EndFunc ;==>_EnterSetName ; ----------------------------------------------- Observations 1) The gist is, anything other than "4" is to be rejected. 2) Thus, anything 3-or-less is rejected and anything 5-or-greater is rejected! Comments, anyone? Edited Thursday at 04:12 AM by mr-es335 mr-es335 Sentinel Music Studios Link to comment Share on other sites More sharing options...
ioa747 Posted Thursday at 04:17 AM Share Posted Thursday at 04:17 AM (edited) Good day. #include <MsgBoxConstants.au3> Example() Func Example() ;ClipPut("F:\") ;ClipPut("F:\Audio\") ;ClipPut("F:\Audio\Type_1") ;ClipPut("F:\Audio\Type_1\AllMe") ;ClipPut("F:\Audio\Type_1\AllMe\AllThem") ;ClipPut("F:\Audio\Type_1\AllMe\AllThem\AllUs") Local $_CompletePath = InputBox("Notice!", "Enter the complete path...", "", " M", 200, 130) Local $aPaths = StringSplit($_CompletePath, "\") ; Split the string of folder names using the delimiter "\" and the default flag value. If $aPaths[0] = 4 Then If $aPaths[1] = "F:" And $aPaths[2] = "Audio" And StringRegExp($aPaths[3], "Type_[1-2]") Then Local $MyPath = $aPaths[1] & "\" & $aPaths[2] & "\" &$aPaths[3] & "\" & $aPaths[4] MsgBox(0, "", "Great!! My Path:" & @CRLF & $MyPath) Return EndIf EndIf MsgBox($MB_SYSTEMMODAL, "", "Nope!") EndFunc ;==>Example one step more #include <MsgBoxConstants.au3> $sMyPath = Example() If @error Then MsgBox($MB_SYSTEMMODAL, "", "Nope!") Else MsgBox(0, "", "Great!! My Path:" & @CRLF & $sMyPath) EndIf Func Example() ;ClipPut("F:\") ;ClipPut("F:\Audio\") ;ClipPut("F:\Audio\Type_1") ;ClipPut("F:\Audio\Type_1\AllMe") ;ClipPut("F:\Audio\Type_1\AllMe\AllThem") ;ClipPut("F:\Audio\Type_1\AllMe\AllThem\AllUs") Local $_CompletePath = InputBox("Notice!", "Enter the complete path...", "", " M", 200, 130) Local $aPaths = StringSplit($_CompletePath, "\") ; Split the string of folder names using the delimiter "\" and the default flag value. If $aPaths[0] = 4 Then If $aPaths[1] = "F:" And $aPaths[2] = "Audio" And StringRegExp($aPaths[3], "Type_[1-2]") Then Local $Result = $aPaths[1] & "\" & $aPaths[2] & "\" &$aPaths[3] & "\" & $aPaths[4] ;~ MsgBox(0, "", "Great!! My Path:" & @CRLF & $Result) Return $Result EndIf EndIf ;~ MsgBox($MB_SYSTEMMODAL, "", "Nope!") Return SetError(1, 0, "") EndFunc ;==>Example Edited Thursday at 04:46 AM by ioa747 I know that I know nothing 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