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

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

     

     


    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.