Chimaera Posted February 22, 2014 Share Posted February 22, 2014 Ok ive been messing about with this tonight as i need to know whether a folder exists before attempting to move files from it Now from the help file it says this Failure: "" (empty string) and sets the @error flag to 1 if user cancels/closes the window. Which to me says that @error is either "" or 1, but the below code doesn't work. I have tried with Switch and Case and those kind of things but this example fails If FileExists("F:\") Then $sSourceSelect = FileSelectFolder("Choose A Backup.", "F:\", 2) ;~ ConsoleWrite("Backup Files = " & $sSourceSelect & @CRLF) If @error = 1 Then MsgBox($MB_ICONWARNING, "Selection Error", "User Cancelled Operation", 4) ElseIf @error = "" Then MsgBox($MB_ICONWARNING, "Selection Error", "Destination Path Error", 4) EndIf ConsoleWrite("Error Is = " & @error & @CRLF) Else MsgBox($IDOK, "Path Error", "Backup Path Not Found") EndIf So am i reading the help file wrong or is it ambiguous? If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2014 Moderators Share Posted February 22, 2014 Chimaera, i reading the help file wrongI am afraid so. If the user cancels the return value is an empty string and @error will be set to 1. So you need something like this:#include <MsgBoxConstants.au3> If FileExists("F:\") Then $sSourceSelect = FileSelectFolder("Choose A Backup.", "F:\", 2) If @error = 1 Then MsgBox($MB_ICONWARNING, "Selection Error", "User Cancelled Operation", 4) Else MsgBox($MB_ICONWARNING, "Selection", $sSourceSelect, 4) EndIf Else MsgBox($IDOK, "Path Error", "Backup Path Not Found") EndIfAll clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Chimaera Posted February 22, 2014 Author Share Posted February 22, 2014 Ok that's what i had to start with... I couldn't separate it which is why i was trying the above. On a slightly different note UNC paths are not supported. If you think that user's may choose files on a UNC path then the path needs to be mapped as a drive first. The drive i will be aiming at at work is added as a network drive so this should be ok y? Because i need UNC to avaoid long filename problems we are having. And one last thought is there a way to seperate the final folder from the path? F:MoviesSaves becomes Saves ? Then i can add it to the destination path to copy the backup to.. Im sure ive seen this somewhere but i cant find it If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2014 Moderators Share Posted February 22, 2014 Chimaera,No idea about networks, sorry. But I can help with the other bit: $sPath = "F:\Movies\Saves" $sExtract = StringRegExpReplace($sPath, "^.*\\", "") ConsoleWrite($sPath & @CRLF & $sExtract & @CRLF)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
trancexx Posted February 22, 2014 Share Posted February 22, 2014 Never check @error for specific value, unless it's absolute necessity for such thing. Just check wheter @error is set. That way your code will be forward compatible. The documentation for the built-in functions often makes mistake saying @error is set to 1, when in fact the correct should have be that @error is set. czardas 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Chimaera Posted February 22, 2014 Author Share Posted February 22, 2014 (edited) Erm question If i cant check for a specific error i.e. @error = 1 How do i separate them if there is multiple ones and i can only check for If @error Then Im aware that FileSelectFolder does,t have multiple but im sure you get what i mean? Edited February 22, 2014 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2014 Moderators Share Posted February 22, 2014 Chimaera,trancexx did say "unless it's absolute necessity". Basically if all you are interested in is whether an error occurred then just check if @error is set (i.e. is non-zero) and you will always get the correct response regardless of how the macro is actually set - if you really need to know what the error was when there are several possibilities then you will need to test the actual value of the macro and keep the code up to date with those values returned by the function. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted February 22, 2014 Share Posted February 22, 2014 (edited) First check for an error and then decide what to do after that. ; Global $gERROR = 0 _Thingumajig() If @error Then ; OMG - What to do now? $gERROR = @error ; Remember the error occured. EndIf Func _Thingumajig() SetError(3) EndFunc ConsoleWrite($gERROR & @LF) Edited February 22, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Chimaera Posted February 22, 2014 Author Share Posted February 22, 2014 (edited) So basically check if it exists then subdivide to find which one $sErrorCheck = @error If $sErrorCheck = 1 Then etc etc czardus beat me to it Edited February 22, 2014 by Chimaera czardas 1 If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
czardas Posted February 22, 2014 Share Posted February 22, 2014 (edited) Make sure you do not reset the @error macro value by entering a new function before you have grabbed the necessary error code - if you need to. Because functions are often called many times in a typical script, it's much more efficient to simply check for all possible errors in one hit. Edited February 22, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
kylomas Posted February 22, 2014 Share Posted February 22, 2014 another possible construct... #include <array.au3> ;local $aTMP = [[123,456],['a','b','c'],[1],[1,2,3,4,5]] local $aTMP _arraydisplay($aTMP) switch @error case 0 case else ConsoleWrite('failure - error code = ' & @error & @LF) endswitch Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Chimaera Posted February 22, 2014 Author Share Posted February 22, 2014 Thx to all If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Solution czardas Posted February 22, 2014 Solution Share Posted February 22, 2014 (edited) You can see the slight speed advantage (when no error occurs) of using a conditional statement in the following example. I often use a switch statement after a conditional, but the code can also get bloated. The code posted by kylomas is nice and neat. Do what suits the situation. ; Local $iTimer $iTimer = TimerInit() For $i = 1 To 100000 _Thingumajig() Switch @error ; Slightly slower case 0 case 1 EndSwitch Next ConsoleWrite(TimerDiff($iTimer) & @LF) $iTimer = TimerInit() For $i = 1 To 100000 _Thingumajig() If @error Then ; Slightly faster using a conditional Switch @error case 1 EndSwitch EndIf Next ConsoleWrite(TimerDiff($iTimer) & @LF) Func _Thingumajig() EndFunc Edited February 22, 2014 by czardas operator64 ArrayWorkshop 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