GPinzone

FileOpenDialog multi-files: extra backslash at root directory

4 posts in this topic

#1 ·  Posted (edited)

I'm following this example:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

; Browse for files
Local $sFileOpenDialog = FileOpenDialog($sMessage, @DesktopDir, "All Files (*.*)", BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))
; Check what type of return we get from the function
If @error Then ; Complete fail
    MsgBox($MB_SYSTEMMODAL, "Error", "Selection failed")
Else ; Check for multiple return which will have delimiters
    If StringInStr($sFileOpenDialog, "|") Then
        ; Multiple files selected, so need to create an array
        $aFileSplit = StringSplit($sFileOpenDialog, "|")
        ; And then loop through the array
        For $i = 2 To $aFileSplit[0] ; Note starting at [2], because [0] is the count and [1] is the path
            ; You need to recreate the full path on each pass
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST)
        Next
    Else
        ; Only a single file selected, so copy immediately
        FileCopy($sFileOpenDialog, $DIR_DEST)
    EndIf
EndIf

The output for multiple files works fine except when selecting files at the root of a drive. The format will be "U:\\filename.ext" instead of"U:\filename.ext" I'm surmising this is because FileOpenDialog returns a path with a trailing "\" when at the root directory, but not in sub-directories.

I know I could strip off the trailing "\" on $aFileSplit[1], but perhaps there's something better to do?

Edited by GPinzone

Gerard J. Pinzonegpinzone AT yahoo.com

Share this post


Link to post
Share on other sites



GPinzone,

Why not use StringRight to check if $aFileSplit[1] ends in a "\" and then not add the additional "\" if it does? Something like this should work (untested):

; You need to recreate the full path on each pass
FileCopy( $aFileSplit[1] & ( ( If StringRight($aFileSplit[1], 1) = "\") ? ("") : ("\") ) & $aFileSplit[$i], $DIR_DEST)
;                          Ternary operator to add either nothing or a "\" as required

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

#3 ·  Posted (edited)

Yes, I'm sure that would work. However, doesn't this seem like a (minor) bug of the FileOpenDialog function?

EDIT: Another idea for a workaround...

; Multiple files selected, so need to create an array
$aFileSplit = StringSplit($sFileOpenDialog, "|")
If StringRight($aFileSplit[1], 1) <> '\' Then
  $aFileSplit[1] &= "\"
EndIf

Then remove the "\" from the later concatenation.

Edited by GPinzone

Gerard J. Pinzonegpinzone AT yahoo.com

Share this post


Link to post
Share on other sites

GPinzone,

I do not see it as a bug. The various @*Dir macros within AutoIt also only have a trailing "\" when dealing with a root folder. In  fact I seem to remember that it is a Windows standard and not an AutoIt one - although I am quite ready to be proved wrong.

And your suggestion is equally valid as a solution- there are several ways to skin this particular cat.

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

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