Jump to content
Tom Wellige

Function: GetFilesInFolder

Recommended Posts

This post is taken from the Swyx Forum Archive (2007-2014) and was originally posted 12.08.2010 by me

 

The following function fills a VBScript 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...

To use the function within your call routing script, just copy&paste it into the "Start" block.

 

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

 

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)

		PlaySound Announcements(i)

	Next

End If

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

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

Loading...

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