GPinzone Posted October 10, 2017 Share Posted October 10, 2017 (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 October 10, 2017 by GPinzone Gerard J. Pinzonegpinzone AT yahoo.com Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 10, 2017 Moderators Share Posted October 10, 2017 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 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...
GPinzone Posted October 10, 2017 Author Share Posted October 10, 2017 (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 October 10, 2017 by GPinzone Gerard J. Pinzonegpinzone AT yahoo.com Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 10, 2017 Moderators Share Posted October 10, 2017 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 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...
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