PINTO1927 Posted January 5, 2017 Posted January 5, 2017 Hello guys, I'm working on this script: Case $BTN Global $URL = FileOpenDialog("IMPORT FILE", $DESKTOP, "ALL FORMAT (*)", 4) $DIR_DEST = "C:\DIR-WORK\list\IMPORT_DOC\" DirCreate($DIR_DEST) Local $LINE For $t = 1 To $URL[0] _FileReadToArray($URL[$t], $LINE) For $u = 1 To $LINE[0] FileCopy($URL[$u], $DIR_DEST) Next Next the selected files via OpenFileDialog must be copied to the folder $DIR_DEST.
Moderators Melba23 Posted January 5, 2017 Moderators Posted January 5, 2017 PINTO1927, Read the Help file to see how the FileOpenDialog return is formatted (Hint: it is not an array): Quote Success: the full path of the file(s) chosen. Results for multiple selections are "Directory|file1|file2|...". So you need to do some work on the return before you use it in a loop. 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
Skeletor Posted July 16, 2017 Posted July 16, 2017 For those interested in the code, see below: Local $sFileOpenDialog = FileOpenDialog($sMessage, @DesktopDir, "All Files (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) ;Browse for files $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF) ;Replace filter with break. See helpfile for more info FileWrite($pathtofile, $sFileOpenDialog) ;Grab list to file $openfile = FileOpen($pathtofile) ;Open the file $FileRead = FileReadLine($pathtofile) ;Read each line from the file FileCopy($FileRead, $pathtofile) ;Copy each file as you read the file line FileClose($openfile) ;Close the file My explanation is not the best however this should get you going... Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI
Skeletor Posted July 16, 2017 Posted July 16, 2017 Oh, and @Melba23 was right, you dont need an array. Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI
Moderators Melba23 Posted July 16, 2017 Moderators Posted July 16, 2017 (edited) Skeletor, Why on earth do you write the return to a file and then read it? Why not just convert the return directly to an array and loop through it? #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 M23 Edited July 16, 2017 by Melba23 Corrected style syntax 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
Skeletor Posted July 17, 2017 Posted July 17, 2017 Melba23 Because I didn't know that and it was the only thing I could think of. I'm just starting out with autoit btw. Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI
mr-es335 Posted October 25, 2023 Posted October 25, 2023 (edited) Melba23, Thank you for the "workable' sampling that you have provided! I did notice though, and please forgive my neophyte-ness here, I did receive two errors when launching the sampling your provided. 1) There was apparently, no variable defined for $sMessage 2 There was apparently, no variable defined for $DIR_DEST Once these were updated, the sampling worked as what I do believe is expected. #include <FileConstants.au3> #include <MsgBoxConstants.au3> Local Const $sMessage = "Select Sessions Files" Local $SRC_DEST="E:\Desktop\Sessions" Local $DIR_DEST="E:\Desktop\Session_Master\Sets\Type_1" Local $sFileOpenDialog = FileOpenDialog($sMessage, $SRC_DEST, "Sessions (*.edl)", BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT)) If @error Then ; Complete fail MsgBox($MB_SYSTEMMODAL, "Error", "Selection failed") Else If StringInStr($sFileOpenDialog, "|") Then $aFileSplit = StringSplit($sFileOpenDialog, "|") For $i = 2 To $aFileSplit[0] FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST) Next Else FileCopy($sFileOpenDialog, $DIR_DEST) EndIf EndIf Observations: As can be seen, I have added lines 4, 6 and 7 and have updated line 9 to meet my particular requirements. Thank you so very much Melba23, for the above...and which has saved me "tons" of work!! Edited October 25, 2023 by mr-es335 mr-es335 Sentinel Music Studios
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