Jump to content

Copy multi file with FileOpenDialog


PINTO1927
 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • 6 months later...

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 Regards
Skeletor

"Coffee: my defense against going postal."

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI

Link to comment
Share on other sites

  • Moderators

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 by Melba23
Corrected style syntax

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • 6 years later...

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 by mr-es335
Link to comment
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
 Share

×
×
  • Create New...