Jump to content
Sign in to follow this  
Chimaera

FileSelectFolder and exit codes?

Recommended Posts

Chimaera

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?

 

Share this post


Link to post
Share on other sites
Melba23

Chimaera,

 

i reading the help file wrong

I 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")
EndIf
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Chimaera

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

Share this post


Link to post
Share on other sites
Melba23

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
trancexx

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.

  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Chimaera

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 by Chimaera

Share this post


Link to post
Share on other sites
Melba23

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Chimaera

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 by Chimaera
  • Like 1

Share this post


Link to post
Share on other sites
czardas

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 by czardas

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
czardas

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 by czardas

Share this post


Link to post
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
Sign in to follow this  

×