Jump to content

_FileListToArray issue


Go to solution Solved by pixelsearch,

Recommended Posts

Good day,

In the following script:

; -----------------------------------------------
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Global $g_T2SetName = "C"
Global $g_T2SourceFolder = "F:\Audio\Type_2\wav"
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_CreateT2Data()
; -----------------------------------------------
Func _CreateT2Data()
    ; Ask the user if they want to create T2 data from .wav data
    Local $confirmCreate = MsgBox(4, "NOTICE!", "Create T2 Data from .wav data?")
    ; ------------------------------------------------------
    If $confirmCreate = 6 Then ; If "Yes" is selected
        ; Prompt the user to select the source folder containing the .wav file data
        Local $sMessage = "Select .wav data..."
        ; -----------------------------------------------
        ;Local $WorkingDir = "F:\Audio\Type_2\" & $g_T2SetName
        Local $sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio\Type_2\" & $g_T2SetName & "\", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
        ConsoleWrite("$sFileOpenDialog = " & $sFileOpenDialog & @CRLF)
        ; -----------------------------------------------
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "", "No .wav file(s) were selected.")
            ; -----------------------------------------------
            FileChangeDir(@ScriptDir)
        Else
            FileChangeDir(@ScriptDir)
            ; -----------------------------------------------
            $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
        EndIf
        ; ------------------------------------------------------
        ; Prompt the user to select the destination folder for the .edl file data
        Local $destMessage = "Select the Destination folder for the .edl file(s)..."
        Local $destFolder = FileSelectFolder($destMessage, "F:\Audio\Type_2")
        ; -----------------
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No destination folder selected. Exiting.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Store the list of .wav file data from the selected source folder
        Local $wavFiles = _FileListToArray($sFileOpenDialog, "*.wav", $FLTA_FILES)
        ConsoleWrite("The selected source folder = " & $g_T2SourceFolder & @CRLF)
        ConsoleWrite("The selected source data = " & $wavFiles)
        ; -----------------
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No .wav file(s) were selected.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Specify the path to the master .edl file
        Local $masterEdlFile = "G:\Session_Master\Show\Session_Data\Type2.edl" ;"G:\Session_Master\Show\Session_Data\Type2.edl"
        ; -----------------
        If Not FileExists($masterEdlFile) Then
            MsgBox($MB_ICONERROR, "Error", "The Type2.edl file was not found.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Process each of the .wav file data and create corresponding .edl data file
        For $i = 1 To $wavFiles[0]
            Local $wavFileName = $wavFiles[$i]
            Local $wavBaseName = StringTrimRight($wavFileName, 4) ; Remove the ".wav" extension
            ; -----------------
            ; Destination .edl file path for each .wav file
            Local $newEdlFile = $destFolder & "\" & $wavBaseName & ".edl"
            ; -----------------
            ; Copy the master .edl file and rename it for each .wav file
            FileCopy($masterEdlFile, $newEdlFile, $FC_OVERWRITE)
        Next
        ; -----------------
        ;FileDelete($destFolder & "\Type2.edl)
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success", "The .edl file(s) have been created successfully.")
        ; -----------------
    ElseIf $confirmCreate = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "Operation cancelled by the user.")
    EndIf
EndFunc   ;==>_CreateT2Data
; -----------------------------------------------

...the variable "$wavFiles" does not appear to be storing any data?!? Why?

; Store the list of .wav file data from the selected source folder
        Local $wavFiles = _FileListToArray($sFileOpenDialog, "*.wav", $FLTA_FILES)
        ConsoleWrite("The selected source folder = " & $g_T2SourceFolder & @CRLF)
        ConsoleWrite("The selected source data = " & $wavFiles)

PS: I am completely stumped here!!

Any assistance in this matter would be greatly appreciated!

 

 

Link to comment
Share on other sites

ioa747,

Thanks.

I see that the first example is from the HelpFile.

Not too sure where to place the second example?

Note: Even though I know that I have selected .wav data, I still receive the error, "No .wav file(s) were selected." Why?
• Why is no data being selected?

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

4 hours ago, mr-es335 said:

...the variable "$wavFiles" does not appear to be storing any data?!? Why?

From your script:

Local $sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio\Type_2\" & $g_T2SetName & "\", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
.
.
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
.
.
Local $wavFiles = _FileListToArray($sFileOpenDialog, "*.wav", $FLTA_FILES)

 

The help file's description for _FileListToArray() is:  Lists files and\or folders in a specified folder with wildcard selection options. (similar to the DIR command)

Looking at your script, it makes me think that you made an incorrect inference as to what the _FileListToArray() function does.  Meaning, you thought it takes as input a string containing a list of file names and put them into an array.  According to the logic in your script, that's what's in $sFileOpenDialog, a string containing a list of file names (one per line).  That is not what the first parameter of the _FileListToArray() function should be.  It should be a path to a folder.  So that is why the function fails.

If you want the files that were selected from the FileOpenDialog put into an array, _FileListToArray() is not the way to do it.  I would use a function like _ArrayAdd() or _ArrayFromString().

 

Link to comment
Share on other sites

TheXman,

Thanks for the reply...appreciated!

I  was attempting to modify the following script so that any-and-all existing data is NOT overwritten...

; ------------------------------------------------------
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
; ------------------------------------------------------
_CreateT2Data()
; ------------------------------------------------------
Func _CreateT2Data()
    ; Ask the user if they want to create T2 data from .wav data
    Local $confirmCreate = MsgBox(4, "NOTICE!", "Create T2 Data from .wav data?")
    ; ------------------------------------------------------
    If $confirmCreate = 6 Then ; If "Yes" is selected
        ; Prompt the user to select the source folder containing the .wav file data
        Local $sourceMessage = "Select Source folder..."
        Local $sourceFolder = FileSelectFolder($sourceMessage, "F:\Audio\Type_2")
        ; -----------------
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No folder selected. Exiting.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Prompt the user to select the destination folder for the .edl file data
        Local $destMessage = "Select Destination folder for the .edl files..."
        Local $destFolder = FileSelectFolder($destMessage, "F:\Audio\Type_2")
        ; -----------------
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No destination folder selected. Exiting.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Store the list of .wav files from the selected source folder
        Local $wavFiles = _FileListToArray($sourceFolder, "*.wav", $FLTA_FILES)
        ; -----------------
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No .wav files found in the selected folder.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Specify the path to the master .edl file
        Local $masterEdlFile = "G:\Session_Master\Show\Session_Data\Type2.edl"
        ; -----------------
        If Not FileExists($masterEdlFile) Then
            MsgBox($MB_ICONERROR, "Error", "The Type2.edl file was not found.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Process each of the .wav file data and create corresponding .edl data file
        For $i = 1 To $wavFiles[0]
            Local $wavFileName = $wavFiles[$i]
            Local $wavBaseName = StringTrimRight($wavFileName, 4) ; Remove the ".wav" extension
            ; -----------------
            ; Destination .edl file path for each .wav file
            Local $newEdlFile = $destFolder & "\" & $wavBaseName & ".edl"
            ; -----------------
            ; Copy the master .edl file and rename it for each .wav file
            FileCopy($masterEdlFile, $newEdlFile, $FC_OVERWRITE)
        Next
        ; -----------------
        ;FileDelete($destFolder & "\Type2.edl)
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success", "All .edl files have been created successfully.")
        ; -----------------
    ElseIf $confirmCreate = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "Operation cancelled by the user.")
    EndIf
EndFunc   ;==>_CreateT2Data
; ------------------------------------------------------

In the above script, the line, "Local $wavFiles = _FileListToArray($sourceFolder, "*.wav", $FLTA_FILES)" appears to be functioning as it should?!?

What I require is to be able to select one or more data files, and then, to have only those selected data files being "acted upon".

I do hope that this makes sense?

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

 

; https://www.autoitscript.com/forum/topic/212428-_filelisttoarray-issue/?do=findComment&comment=1538168

; -----------------------------------------------
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Global $g_T2SetName = "C"
Global $g_T2SourceFolder = "F:\Audio\Type_2\wav"
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_CreateT2Data()
; -----------------------------------------------
Func _CreateT2Data()
    ; Ask the user if they want to create T2 data from .wav data
    Local $confirmCreate = MsgBox(4, "NOTICE!", "Create T2 Data from .wav data?")
    ; ------------------------------------------------------
    If $confirmCreate = 6 Then ; If "Yes" is selected
        ; Prompt the user to select the source folder containing the .wav file data
        Local $sMessage = "Select .wav data..."
        ; -----------------------------------------------
        ;Local $WorkingDir = "F:\Audio\Type_2\" & $g_T2SetName
        Local $sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio\Type_2\" & $g_T2SetName & "\", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
        ConsoleWrite("$sFileOpenDialog = " & $sFileOpenDialog & @CRLF)
        ; -----------------------------------------------
        ; Store the list of .wav file data from the selected source folder
        Local $aWavFiles = StringSplit($sFileOpenDialog, "|")
        _ArrayDisplay($aWavFiles)
        ; -----------------------------------------------

       FileChangeDir(@ScriptDir)
       If @error Then
            MsgBox($MB_SYSTEMMODAL, "", "No .wav file(s) were selected.")
        Else
            $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
        EndIf
        ; ------------------------------------------------------
        ; Prompt the user to select the destination folder for the .edl file data
        Local $destMessage = "Select the Destination folder for the .edl file(s)..."
        Local $destFolder = FileSelectFolder($destMessage, "F:\Audio\Type_2")
        ConsoleWrite("$destFolder=" & $destFolder & @CRLF)
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No destination folder selected. Exiting.")
            Return
        EndIf
        ; ------------------------------------------------------
;~         ; Store the list of .wav file data from the selected source folder
;~         Local $wavFiles = _FileListToArray($sFileOpenDialog, "*.wav", $FLTA_FILES)
;~      _ArrayDisplay($wavFiles)
;~         If @error Then
;~             MsgBox($MB_ICONERROR, "Error: " & @error, "No .wav file(s) were selected.")
;~             Return
;~         EndIf
;~      _ArrayDisplay($wavFiles)
;~      ConsoleWrite("The selected source folder = " & $g_T2SourceFolder & @CRLF)
;~         ConsoleWrite("The selected source data = " & $wavFiles)
        ; ------------------------------------------------------
        ; Specify the path to the master .edl file
        Local $masterEdlFile = "G:\Session_Master\Show\Session_Data\Type2.edl" ;"G:\Session_Master\Show\Session_Data\Type2.edl"
        ; -----------------
        If Not FileExists($masterEdlFile) Then
;~             MsgBox($MB_ICONERROR, "Error", "The Type2.edl file was not found.")
            ConsoleWrite("! The Type2.edl file was not found." & @CRLF)
;~             Return
        EndIf
        ; ------------------------------------------------------
        ; Process each of the .wav file data and create corresponding .edl data file
        Local $sWavFolder = $aWavFiles[1]
        ConsoleWrite("$sWavFolder=" & $sWavFolder & @CRLF)

        For $i = 1 To $aWavFiles[0]
            Local $wavFileName = $sWavFolder & "\" & $aWavFiles[$i]
            ConsoleWrite($i & ") $wavFileName=" &  $aWavFiles[$i] & @CRLF)
            Local $wavBaseName = StringTrimRight( $aWavFiles[$i], 4) ; Remove the ".wav" extension
            ; -----------------
            ; Destination .edl file path for each .wav file
            Local $newEdlFile = $destFolder & "\" & $wavBaseName & ".edl"
            ConsoleWrite("$newEdlFile=" & $newEdlFile & @CRLF)
            ; -----------------
;~          ; Copy the master .edl file and rename it for each .wav file
;~          FileCopy($masterEdlFile, $newEdlFile, $FC_OVERWRITE)
            FileWrite($newEdlFile, "master .edl")

        Next
        ; -----------------
        ;FileDelete($destFolder & "\Type2.edl)
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success", "The .edl file(s) have been created successfully.")
        ; -----------------
    ElseIf $confirmCreate = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "Operation cancelled by the user.")
    EndIf
EndFunc   ;==>_CreateT2Data
; -----------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

ioa747,

Thanks for the reply and the updated script...very much appreciated...as are YOU!

To begin with, why are the various sections of the script "commented out", and yet, there other sections added?

I am not at all sure what the script you provided is supposed to do...as it would appear - TO ME ANYHOW, that the script "does nothing!"
• This comment is not meant to be construed as a slight again you, ioa747!! Indeed, you have been a "GS" to me!! ...or... "You are wonderfully helpful, especially in my time of need!"
• Maybe the script DOES do something, but remember, I am an "ID-10-T" here.

In the "_CreateT2Data()" scripts, as noted above, this script:

1) Looks at the data located in the selected source "wav" folder
2) Stores that data content in an array
3) Accesses a specific "Type_# " data file [...there are four] ...in this case a "Type_2" data file
4) Takes the name of each of the stored array items, and creates "named" copies of of the "Type_2 " data file
5) Places that "copied-and-renamed data" in an "edl" folder
6) These data files will be subsequently "updated" with the data located in the "wave" folder.

That is, as they say "It!"

However, and this an important however, I does NOT want to overwrite previously updated data, which is what the "_CreateT2Data()" script CURRENTLY DOES!!!

In this "updated script", what I want to to is to "ADD"  files to the existing data - without altering that existing data! However, this is what the current "_CreateT2Data()" script does.

I have been literally "racking my brain" as to a resolve - and with NO APPARENT SUCCESS!!

As always, any assistance in this matter would be greatly appreciated!

 

 

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

your main problem is that the wav files do not appear

why this happens was explained above by TheXman

so in this case two things could be done

  • or with the FileSelectFolder you would select a folder and the function _FileListToArray  would do the work (find the wav files)
  • or you will properly handle the result given by function FileOpenDialog

That's I tried with the above script
to show you how to extract wave files from the result of MultiSelect FileOpenDialog and output the name of each file

now why that didn't do something for you I don't know

 

I know that I know nothing

Link to comment
Share on other sites

TheXman and ios747,

May I ask why Example 1 "works" and Example 2 "does not work"?

; Example 1
; -----------------------------------------------
Local $sourceFolder = FileSelectFolder($sourceMessage, "F:\Audio\Type_2")
; -----------------------------------------------
Local $wavFiles = _FileListToArray($sourceFolder, "*.wav", $FLTA_FILES)
; -----------------------------------------------
For $i = 1 To $wavFiles[0]
    Local $wavFileName = $wavFiles[$i]
    Local $wavBaseName = StringTrimRight($wavFileName, 4)
    ; -----------------
    Local $newEdlFile = $destFolder & "\" & $wavBaseName & ".edl"
    ; -----------------
    FileCopy($masterEdlFile, $newEdlFile, $FC_OVERWRITE)
Next
; -----------------
MsgBox($MB_ICONINFORMATION, "Success", "All .edl files have been created successfully.")
; -----------------------------------------------
; -----------------------------------------------
; Example 2
; -----------------------------------------------
Local $sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio\Type_2\" & $g_T2SetName & "\", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
; -----------------------------------------------
Local $wavFiles = _FileListToArray($sFileOpenDialog, "*.wav", $FLTA_FILES)
; -----------------------------------------------
For $i = 1 To $wavFiles[0]
    Local $wavFileName = $wavFiles[$i]
    Local $wavBaseName = StringTrimRight($wavFileName, 4)
    ; -----------------
    Local $newEdlFile = $destFolder & "\" & $wavBaseName & ".edl"
    ; -----------------
    FileCopy($masterEdlFile, $newEdlFile, $FC_OVERWRITE)
Next
; -----------------
MsgBox($MB_ICONINFORMATION, "Success", "The .edl file(s) have been created successfully.")
; -----------------------------------------------

The above two examples are identical - with the exception of the following:

Local $sourceFolder = FileSelectFolder($sourceMessage, "F:\Audio\Type_2")...AND...

Local $sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio\Type_2\" & $g_T2SetName & "\", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))

Link to comment
Share on other sites

4 hours ago, ioa747 said:

now why that didn't do something for you I don't know

Well! I misunderstood what you were referring to...following is the result...

I guess my "real" question is, "What do I do with the results of the FileOpenDialog?"

Result.png

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

 

#include <Array.au3>
#include <FileConstants.au3>

Local $g_T2SetName = "C"
Local $sMessage = "Select .wav data..."
Local $sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio\Type_2\" & $g_T2SetName & "\", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
ConsoleWrite("$sFileOpenDialog = " & $sFileOpenDialog & @CRLF)

Local $aWavFiles = StringSplit($sFileOpenDialog, "|")
_ArrayDisplay($aWavFiles)

; ------------------------------------------------------
; Process each of the .wav file data and create corresponding .edl data file
Local $sWavFolder = $aWavFiles[1]
ConsoleWrite("$sWavFolder=" & $sWavFolder & @CRLF)

Local $destFolder = "F:\Audio\Type_2" ; *** <- example

For $i = 2 To $aWavFiles[0]
    Local $wavFileName = $sWavFolder & "\" & $aWavFiles[$i]
    Local $wavBaseName = StringTrimRight($aWavFiles[$i], 4) ; Remove the ".wav" extension
    Local $newEdlFile = $destFolder & "\" & $wavBaseName & ".edl"
    ConsoleWrite($i & ") $newEdlFile=" & $newEdlFile & @CRLF)
Next

is this ok?

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

ioa747,

I just discover that it was YOU that assisted me sometime ago with a "NirCmd" script!!
• Man, this "thing" goes back a bit! [Click_me]

If I can say this in as simple-a-manner-as-is-possible, the _CreateT1Data() accessed the contents of the ENTIRE folder!

All that I want to be able to do now, is to access "only those files that I have previously selected!"

Thus, the change from:

Local $sourceFolder = FileSelectFolder($sourceMessage, "F:\Audio\Type_2")

...to...

Local $sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio\Type_2\" & $g_T2SetName & "\", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))

At least, I hope that the employment of "FileOpenDialog" IS CORRECT?!?

 

Link to comment
Share on other sites

ioa747,

It "appears" that what is being accomplished here is the renaming of the .wav file to .edl.

Would this be a correct assertion?
• See below...

PS: I DID update the script to employ the correct destination path:

Local $destFolder = "F:\Audio\Type_2\edl" ; *** <- example

4.png

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

this is the construction of the name

Local $newEdlFile = $destFolder & "\" & $wavBaseName & ".edl"

with   FileCopy($masterEdlFile, $newEdlFile, $FC_OVERWRITE)    Make copy
with   FileWrite($newEdlFile, "master .edl")    Make .txt file with text  "master .edl"  inside

 

 

 

I know that I know nothing

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