Jump to content
  • GetFilesInFolder()

    GetFilesInFolder()

    Lua   → VBScript

     

    The following function fills a table with the names of all files in a given folder (incl. subfolders). 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.

     

    Please note: the Lua Beta Testing versions of SwyxWare (13.1x) do not limit any file access. In the final release version file access will only be permitted in the SwyxWare CPE (customer premise equipment) version. Within the cloud versions (SDC and SwyxON) file access will not be permitted.

     

    ----------------------------------------------------------------
    -- GetFilesInFolder()
    --
    -- Reads all file names in given folder (incl. subfolders) into a table.
    --
    -- Parameter:
    --   sPath          name of path
    --                  file filters incl. wildcards "*" and "?" are allowed
    --                  backslashes in the path name need to get escaped
    --                  i.e. C:\\Anouncements\\*.wav
    --
    -- Return:
    --   table          containing all filenames (incl. path)
    ----------------------------------------------------------------
    function GetFilesInFolder ( sPath )
        PBXScript.OutputTrace ("-----------> GetFilesInFolder( " .. sPath .. " )")
    
        local tFiles = {}
        local p = io.popen('dir "'.. sPath ..'" /b /s')
        for sFile in p:lines() do
            PBXScript.OutputTrace ("sFile = " .. sFile)
            table.insert(tFiles, sFile)
        end
    
        PBXScript.OutputTrace ("<----------- GetFilesInFolder")
    
        return tFiles
    end

     

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

     

    Please note, that you have to escape backslashes in the sFileName parameter. So instead of "C:\Announcements" you have to pass "C:\\Announcements".

     

    You can define a filter within the sPath parameter incl. regular wildcards "*" and "?". For example "C:\\Announcements\\*.wav".

     

     

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

     

    local f = GetFilesInFolder("C:\\Announcements\\*.wav")
    for i = 1, #f do
        PBXCall.PlayMessage(f[i])
    end

     

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

     

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

     

     

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

     

     




    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.