Jump to content

FileOpenDialog Double Source Selection


 Share

Go to solution Solved by Andreik,

Recommended Posts

Good day,

The following script appears to be functioning as expected:

; -----------------------------------------------
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
; -----------------------------------------------
; SECTION A1: First, select an .edl data file
Local Const $sMessage1="Select .edl file"
Local $SRC1="G:\Session_Master\Performance"
Local $sFileOpenDialog1=FileOpenDialog($sMessage1, $SRC1, "Session File (*.edl)", BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))
; -----------------
; SECTION A2: Second, select a .wpd data file
Local Const $sMessage2="Select .wpd file"
Local $SRC2="F:\Audio\Type_1"
Local $sFileOpenDialog2=FileOpenDialog($sMessage2, $SRC2, "Wave File (*.wpd)", BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))
; -----------------------------------------------
; SECTION B: Third, select the destination folder location for both data files
Local Const $sMessage3="Select a Destination folder..."
Local $_Selected_Folder=FileSelectFolder($sMessage3, "E:\Master_Backup\Type_1")
; -----------------------------------------------
; SECTION C1: Fourth, copy the .edl data file
If StringInStr($sFileOpenDialog1, "|") Then
    $aFileSplit=StringSplit($sFileOpenDialog1, "|")
        For $i=2 To $aFileSplit[0]
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $_Selected_Folder)
        Next
    Else
        FileCopy($sFileOpenDialog1, $_Selected_Folder)
EndIf
; -----------------
; SECTION C2: Fifth, copy the .wpd data file
If StringInStr($sFileOpenDialog2, "|") Then
    $aFileSplit=StringSplit($sFileOpenDialog2, "|")
        For $i=2 To $aFileSplit[0]
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $_Selected_Folder)
        Next
    Else
        FileCopy($sFileOpenDialog2, $_Selected_Folder)
EndIf
; -----------------------------------------------

 

My query is, "Can Sections A1/A2 and Sections C1/C2 be amalgamated?

Thanks in advance!

Edited by mr-es335
Errors
Link to comment
Share on other sites

  • Solution

You can definitely have different file type filters to select files from the same directory but sections A1 and A2 can't because merged because you are looking to select files from different directories. Sections C1 and C2 can be grouped more logically and be processed in a single loop but as a matter of code length it will be pretty much the same because FileOpenDialog() returns different kind of results for single and multiple file selections. Here is some sort of merged code but can be done in many ways and I am pretty sure it can be done even better:

Local $aFileSplit1 = StringSplit($sFileOpenDialog1, "|")
Local $aFileSplit2 = StringSplit($sFileOpenDialog2, "|")

; In both dialogs has been selected multiple files
If StringInStr($sFileOpenDialog1, "|") And StringInStr($sFileOpenDialog2, "|") Then
    For $i = 2 To ($aFileSplit1[0] > $aFileSplit2[0] ? $aFileSplit1[0]  : $aFileSplit2[0])
        If $i <= $aFileSplit1[0] Then FileCopy($aFileSplit1[1] & "\" & $aFileSplit1[$i], $_Selected_Folder)
        If $i <= $aFileSplit2[0] Then FileCopy($aFileSplit2[1] & "\" & $aFileSplit2[$i], $_Selected_Folder)
    Next
; Just in first dialog has been selected multiple files
ElseIf StringInStr($sFileOpenDialog1, "|") And Not StringInStr($sFileOpenDialog2, "|")
    For $i = 2 To  $aFileSplit1[0] 
        FileCopy($aFileSplit1[1] & "\" & $aFileSplit1[$i], $_Selected_Folder)
    Next
    FileCopy($sFileOpenDialog2, $_Selected_Folder)
; Just in second dialog has been selected multiple files
ElseIf Not StringInStr($sFileOpenDialog1, "|") And  StringInStr($sFileOpenDialog2, "|")
    For $i = 2 To  $aFileSplit2[0] 
        FileCopy($aFileSplit2[1] & "\" & $aFileSplit2[$i], $_Selected_Folder)
    Next
    FileCopy($sFileOpenDialog1, $_Selected_Folder)
; In both dialogs has been selected a single file
Else
    FileCopy($sFileOpenDialog1, $_Selected_Folder)
    FileCopy($sFileOpenDialog2, $_Selected_Folder)
EndIf

 

The real optimization would be to ask first for the destination directory and then ask in a loop for as many dialog boxes you want for certain file types:

; -----------------------------------------------
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
; -----------------------------------------------
; SECTION B: Third, select the destination folder location for both data files
Local Const $sMessage3="Select a Destination folder..."
Local $_Selected_Folder=FileSelectFolder($sMessage3, "E:\Master_Backup\Type_1")
; -----------------------------------------------

Local $sFileOpenDialog, $aFileSplit
Local $aSources[2][3] = [ _
        ["Select .edl file", "G:\Session_Master\Performance",  "Session File (*.edl)"], _
        ["Select .wpd file", "F:\Audio\Type_1", "Wave File (*.wpd)"] _
    ]

For $Index = 0 To UBound($aSources, 0) - 1
    $sFileOpenDialog = FileOpenDialog($aSources[$Index][0], $aSources[$Index][1], $aSources[$Index][2], BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))
    If StringInStr($sFileOpenDialog, "|") Then
    $aFileSplit = StringSplit($sFileOpenDialog, "|")
        For $i = 2 To $aFileSplit[0]
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $_Selected_Folder)
        Next
    Else
        FileCopy($sFileOpenDialog, $_Selected_Folder)
    EndIf
Next

Maybe it's even better to use a function:

; -----------------------------------------------
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
; -----------------------------------------------
; SECTION B: Third, select the destination folder location for both data files
Local Const $sMessage3="Select a Destination folder..."
Local $_Selected_Folder=FileSelectFolder($sMessage3, "E:\Master_Backup\Type_1")
; -----------------------------------------------

SelectFiles($_Selected_Folder, "Select .edl file", "G:\Session_Master\Performance", "Session File (*.edl)")
SelectFiles($_Selected_Folder, "Select .wpd file", "F:\Audio\Type_1", "Wave File (*.wpd)")

Func SelectFiles($sDestination, $sTitle, $sInitialDir, $sFilter)
    Local $sFileOpenDialog = FileOpenDialog($sTitle, $sInitialDir, $sFilter, BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))
    If StringInStr($sFileOpenDialog, "|") Then
    Local $aFileSplit = StringSplit($sFileOpenDialog, "|")
        For $i = 2 To $aFileSplit[0]
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $sDestination)
        Next
    Else
        FileCopy($sFileOpenDialog, $sDestination)
    EndIf
EndFunc

And most appropriate for your case, to maintain the order of operations would be this:

; -----------------------------------------------
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
; -----------------------------------------------
; SECTION A1: First, select an .edl data file
Local Const $sMessage1="Select .edl file"
Local $SRC1="G:\Session_Master\Performance"
Local $sFileOpenDialog1=FileOpenDialog($sMessage1, $SRC1, "Session File (*.edl)", BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))
; -----------------
; SECTION A2: Second, select a .wpd data file
Local Const $sMessage2="Select .wpd file"
Local $SRC2="F:\Audio\Type_1"
Local $sFileOpenDialog2=FileOpenDialog($sMessage2, $SRC2, "Wave File (*.wpd)", BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))
; -----------------------------------------------
; SECTION B: Third, select the destination folder location for both data files
Local Const $sMessage3="Select a Destination folder..."
Local $_Selected_Folder=FileSelectFolder($sMessage3, "E:\Master_Backup\Type_1")
; -----------------------------------------------
; SECTION C

CopyFiles($sFileOpenDialog1, $_Selected_Folder)
CopyFiles($sFileOpenDialog2, $_Selected_Folder)


Func CopyFiles($sFileOpenDialog, $sDestination)
    If StringInStr($sFileOpenDialog, "|") Then
    Local $aFileSplit = StringSplit($sFileOpenDialog, "|")
        For $i = 2 To $aFileSplit[0]
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $sDestination)
        Next
    Else
        FileCopy($sFileOpenDialog, $sDestination)
    EndIf
EndFunc

 

Edited by Andreik

When the words fail... music speaks.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...