Jump to content
Gold Sponsor: Data-Way IT-Consulting, Austria

  • GetFilesInFolder

    GetFilesInFolder

    VBScript   → Lua

     

    The following function fills an array with the names of a files in a given folder. The names contain the complete path.
    It can be used for example, to get a list of announcement (.wav) files in a folder to play them one after each other. See example code below...

    Please see the Introduction chapter for some usage instructions.

     

    '--------------------------------------------------------------
    ' GetFilesInFolder()
    '
    ' Reads all file names in given folder into a given array
    '
    ' Parameter:
    '   Path         [in]  name of path
    '   FilesArray   [out] array to store all filenames in
    '
    ' Return:
    '   boolean      TRUE  - files found
    '                FALSE - no files found
    '--------------------------------------------------------------
    Function GetFilesInFolder ( Path, ByRef FilesArray )
        PBXScript.OutputTrace "-----------> GetFilesInFolder( " & Path & " )"
    
        Dim bReturn
        bReturn = False
    
        Dim fso, folder, files, file
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set folder = fso.GetFolder(Path)
        Set files = folder.files
    
        Redim FilesArray(0)
        If files.count <> 0 Then
            bReturn = True
            For Each file In files
                Redim Preserve FilesArray(UBound(FilesArray)+1)
                FilesArray(UBound(FilesArray)) = file.path
                PBXScript.OutputTrace CStr(UBound(FilesArray)) & ": " & FilesArray(UBound(FilesArray))
            Next
        End If
    
        Set fso = Nothing
    
        GetFilesInFolder = bReturn
    
        PBXScript.OutputTrace "bReturn = " & bReturn
        PBXScript.OutputTrace "<----------- GetFilesInFolder"
    End Function

     

    This function makes use of the Server Script API function PBXScript.OutputTrace to write trace information into the SwyxServer trace file.

     

     

    The following example code, which could be placed into an Insert Script Code block play all .wav files in a given folder:

     

    Dim Announcements()
    Dim i
    
    If GetFilesInFolder("C:\Announcements\", Announcements) Then
    
        For i = LBound(Announcements) to UBound(Announcements)
    
            PBXCall.PlayMessage Announcements(i)
    
        Next
    
    End If

     

    This exmaple makes use of the Server Script API function PBXCall.PlayMessage function to play a given .wav file.

     

    The .wav files need to be in 16kHz, 16bit, PCM, mono format.

     

     

    This function and the example was initially posted in this forum topic.

     

     


    Tom Wellige
     Share


     Share




    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.