Jump to content
  • 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))
        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)
    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


    User Feedback

    Recommended Comments

    There are no comments to display.

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