Jump to content

Maximum File Limit


 Share

Go to solution Solved by Andreik,

Recommended Posts

Good day,

Back in January of 2017, Melba23 posted the following: [Link]

This sampling has been extremely helpful to me...but I do have a further query....

Line 18 displays the following:

FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST)

What I need to know is "How to cease the file selection when the maximum number of files has been reached?"
• In the present situation, the maximum number of files would be 6.

Any assistance in this matter would be greatly appreciated!

PS: Here is my completed script thus far:

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

Local Const $sMessage = "Select Session Files"

Local $SRC_DEST="F:\Audio\Type_2"
Local $DIR_DEST="G:\Session_Master\Sets\Electric_Guitar\Audio"

Local $sFileOpenDialog = FileOpenDialog($sMessage, $SRC_DEST, "Wave File (*.wav)", 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

    $MyBox=MsgBox(4, "Continue?...", "Yes or No")

    If $MyBox == 6 Then
    $iPID=ShellExecute(@ScriptDir & "\select_type_2.au3")
    ElseIf $MyBox == 7 Then
    $iPID=ShellExecute(@ScriptDir & "\select_wave_files.au3")
    EndIf
EndIf

 

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

What do you mean by maximum number of files? Do you want to stop the copy process after a certain number of files has been copied? Something like this:

For $i = 2 To $aFileSplit[0]
    If $i = 6 Then ExitLoop
    FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST)
Next

 

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

N.B. Good coding practice:

If $MyBox == 6 Then

should be

If $MyBox = 6 Then

because $myBox is an integer. == is used for strict string comparison.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • mr-es335 changed the title to Maximum File Limit

Ok, so let's say that you selected 15 files but you need just 6 files. That means that you need to go from index 2 to index 7 of $aFileSplit. But there is a chance that less than 6 files has been selected, case when you need to run the entire loop. This can be achieved easy in that way:

For $i = 2 To ($aFileSplit[0] < 7 ? $aFileSplit[0] : 7)

Basically if $aFileSplit[0] is less than 7 (1 directory + 6 files) you loop through the entire array, but if there are more indices your loop will end when index 7 is reached. Hope this is what do you want.

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Andriek,

Thanks for the reply...appreciated!

In the original script...

FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST)

What i am thinking of here, is [I would assume] that when the maximum value of "i" is reached that a notice would be displayed indicating that the total number of files has been reached. This notice could either "time out" or provided an OK option.

Again, I do hope that this make sense?

Link to comment
Share on other sites

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

Local Const $sMessage = "Select Session Files"

Local $SRC_DEST="F:\Audio\Type_2"
Local $DIR_DEST="G:\Session_Master\Sets\Electric_Guitar\Audio"

Local $sFileOpenDialog = FileOpenDialog($sMessage, $SRC_DEST, "Wave File (*.wav)", 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]
            If $i > 7 Then  ; After the first 6 files has been copied
                MsgBox(0, 'Limit', 'The file limit has been reached.') ; the message will pop up
                ExitLoop    ; And copy will be canceled for next files
            EndIf
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST)
        Next
    Else
        FileCopy($sFileOpenDialog, $DIR_DEST)
    EndIf

    $MyBox=MsgBox(4, "Continue?...", "Yes or No")

    If $MyBox == 6 Then
    $iPID=ShellExecute(@ScriptDir & "\select_type_2.au3")
    ElseIf $MyBox == 7 Then
    $iPID=ShellExecute(@ScriptDir & "\select_wave_files.au3")
    EndIf
EndIf

This will do what you asked for but I don't get the logic of the code that follows without a context. What about $MyBox and these shell executes?

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Andreik,

As I noted above, I have a folder labeled, "Type_1". This folder contains numerous sub-folders [with the artist's name and relevant audio files] from which to choose from. This data will be "eventually" organized into what I refer to as "Sets" - of which there are a maximum number of 6 files.
• Thought I have provided the "Type_2" menu script the Type_1 menu is identical in functionality.

I want to be able to navigate through any of the available folders to select a specific audio file. When the 6th file has been selected, I need some means of indicating to me that the total number of files has then been met.

The purpose of the MsgBox section is as follows:
• There are two scripts involved here: 1) select_wave_files and 2) select_type_2.
• select_wave_files: Provide menu options for the various "types" of audio files
• select_type_2: The type_2 menu options

$MyBox=MsgBox(4, "Continue?...", "Yes or No")

If $MyBox == 6 Then
    ; If 6 files have not yet been selected, then return to the select_type_2.au3 script and continue.
    $iPID=ShellExecute(@ScriptDir & "\select_type_2.au3")
    ; If 6 files have been selected, then return to the select_wave_files.au3 script
    ElseIf $MyBox == 7 Then
    $iPID=ShellExecute(@ScriptDir & "\select_wave_files.au3")
EndIf

Does this make sense or does this help?

Link to comment
Share on other sites

10 minutes ago, mr-es335 said:

Does this make sense or does this help?

Not really. What happens if first there are selected 3 files and then 11 files? How many sets do you have and when the script really ends? If there are different sets I assume destination directory should change at some point but in your case it doesn't. And why ShellExecute() to run AutoIt scripts instead of including them in your main script with #include? Right now I'm just guessing what do you try to achieve.

When the words fail... music speaks.

Link to comment
Share on other sites

Andreik,

Here is what I have:

1. See image below

2.Code for image [select_wave_files]

; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
; -----------------------------------------------
Local $hGUI=GUICreate("Wave File Selection", 530, 395)
GUISetFont(12, $FW_BOLD, $GUI_FONTNORMAL, "Calibri")
; -----------------------------------------------
Local $_WFSel_T1=GUICtrlCreateButton("Intro_Outro", 20, 20, 150, 25)
; -----------------
Local $idButton_exit=GUICtrlCreateButton("Exit", 190, 20, 150, 25)
; -----------------
GUISetState(@SW_SHOW, $hGUI)
$Pic1=GUICtrlCreatePic("E:\Desktop\Menu\Images\Working.bmp", 360, 20, 150, 355)
; -----------------------------------------------
Local $iPID=0
; -----------------------------------------------
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idButton_exit
ExitLoop
; -----------------------------------------------
Case $_WFSel_T1
$iPID=ShellExecute(@ScriptDir & "\select_type_1.au3")
Exit
; -----------------
EndSwitch
WEnd
; -----------------------------------------------

3. Code for [select_type_1]:

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

Local Const $sMessage = "Select Sessions Files"

Local $SRC_DEST="F:\Audio\Type_1"
Local $DIR_DEST="G:\Session_Master\Sets\Intro_Outro\Audio"

Local $sFileOpenDialog = FileOpenDialog($sMessage, $SRC_DEST, "Wave File (*.wav)", 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]
        If $i = 6 Then ExitLoop
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST)
        ExitLoop
        Next
    Else
        FileCopy($sFileOpenDialog, $DIR_DEST)
    EndIf
    $MyBox=MsgBox(4, "Continue?...", "Yes or No")
    If $MyBox == 6 Then
    $iPID=ShellExecute(@ScriptDir & "\select_type_1.au3")
    ElseIf $MyBox == 7 Then
    $iPID=ShellExecute(@ScriptDir & "\select_wave_files.au3")
    EndIf
EndIf

4. Launching the select_wave_files script navigates me to contents of Image 2.
• From here I can launch any folder and select as many files as I want.
5. I can then continue to exit-and-launch any of the other folders to select other data [see image 3] or exit - which return me back to [select_wave_files]
6. At present I make a "mental note" of the number of files that I have selected.
• When I reach the 6th one, I then select "No" and am returned to [select_wave_files]

 

 

 

1.png

2.png

3.png

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

Definitely we have a language barrier. Anyway here is what I proposed to you:

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

SelectWaveFiles()

Func SelectWaveFiles()
    Local $hGUI = GUICreate("Wave File Selection", 530, 395)
    GUISetFont(12, $FW_BOLD, $GUI_FONTNORMAL, "Calibri")
    Local $_WFSel_T1 = GUICtrlCreateButton("Intro_Outro", 20, 20, 150, 25)
    Local $idButton_exit = GUICtrlCreateButton("Exit", 190, 20, 150, 25)
    $Pic1=GUICtrlCreatePic("E:\Desktop\Menu\Images\Working.bmp", 360, 20, 150, 355)
    GUISetState(@SW_SHOW, $hGUI)
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_exit
                ExitLoop
            Case $_WFSel_T1
                GUISetState(@SW_HIDE, $hGUI)
                SelectType()
                GUISetState(@SW_SHOW, $hGUI)
        EndSwitch
    WEnd
EndFunc

Func SelectType()
    Local Const $sMessage = "Select Sessions Files"
    Local $SRC_DEST="F:\Audio\Type_1"
    Local $DIR_DEST="G:\Session_Master\Sets\Intro_Outro\Audio"
    Local $sFileOpenDialog = FileOpenDialog($sMessage, $SRC_DEST, "Wave File (*.wav)", 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
        $MyBox=MsgBox(4, "Continue?...", "Yes or No")
        If $MyBox == 6 Then
            SelectType()
        Else
            Return
        EndIf
    EndIf
EndFunc

There is no reason to split such a basic code in multiple files when you can have two simple functions that can be further customized to receive source, destination and file type as parameters.

When the words fail... music speaks.

Link to comment
Share on other sites

Andreik,

Believe me, I do understand the importance of/the significance of..."functions".

Coming from a purely "DOS Batch file" environment for many years, I am simply looking for an alternative to only working with the cmd line...thus, "AutoIt!"

The sampling that you have provided is indeed "exquisite"...yet it does not meet the objective to which i am endeavoring to achieve.

As I noted, I simply - if I may use that term, need a method of noting when I have reached the 6th data file - regardless of what sub-folder that data was initially selected from.

For example, I select 1 data file from "Andy Williams" [1], then 3 data files from Eva Cassidy [3+1=4], then 2 data files from Elvis Presley [4+2=6] - I am then told that the maximum number of data files has been reached. I would then be returned to [select_waves_files.au3]

Does this makes sense?

Link to comment
Share on other sites

  • Solution
29 minutes ago, mr-es335 said:

Does this makes sense?

That's even a stronger indication that the best way is to use functions with a global variable to keep track of selected files instead of running different scripts. You can still do it in your way but it's more messy because you have to pass the previous number of selected files to the script as command line argument or to save this info in a file (like ini) and read it when the script run next time.

 

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Andreik,

Firstly...than you for your assistance...it is very much appreciated!

Secondly, though I do understand the significance of "functions", I really do not see an immediate need for them at this point.

The scripts I deploy are rather simple and I feel do not require the need for functions.

Thanks again.

PS: Though my original query was not directly dealt with, I will consider this posting as being "solved".

Link to comment
Share on other sites

Nah, you don't have to mark it solved if doesn't meet your requirements. Somebody may assist you further. Anyway this is what I meant above, if you still want to do it in your way:

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

Local Const $sMessage = "Select Sessions Files"

Local $SRC_DEST="F:\Audio\Type_1"
Local $DIR_DEST="G:\Session_Master\Sets\Intro_Outro\Audio"

Local $sFileOpenDialog = FileOpenDialog($sMessage, $SRC_DEST, "Wave File (*.wav)", BitOr($FD_FILEMUSTEXIST, $FD_MULTISELECT))

If @error Then ; Complete fail
    MsgBox($MB_SYSTEMMODAL, "Error", "Selection failed")
Else
    Local $iCounter = IniRead(@ScriptDir & '\cnt.ini', 'Save', 'Counter', 0)    ; Read previous counter and continue until the limit it's reached
    If StringInStr($sFileOpenDialog, "|") Then
        $aFileSplit = StringSplit($sFileOpenDialog, "|")
        For $i = 2 To $aFileSplit[0]
            FileCopy($aFileSplit[1] & "\" & $aFileSplit[$i], $DIR_DEST)
            $iCounter += 1
            If $iCounter == 6 Then ; Your limit
                IniWrite(@ScriptDir & '\cnt.ini', 'Save', 'Counter', 0) ; Reset counter
                ExitLoop
            EndIf
        ExitLoop
        Next
    Else
        FileCopy($sFileOpenDialog, $DIR_DEST)
        $iCounter += 1
        If $iCounter == 6 Then ; Your limit
            IniWrite(@ScriptDir & '\cnt.ini', 'Save', 'Counter', 0) ; Reset counter
        EndIf
    EndIf
    $MyBox=MsgBox(4, "Continue?...", "Yes or No")
    If $MyBox == 6 Then
        $iPID=ShellExecute(@ScriptDir & "\select_type_1.au3")
    Else
        $iPID=ShellExecute(@ScriptDir & "\select_wave_files.au3")
    EndIf
EndIf

Another way it's to pass the previous counter as command line argument.

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...