I tested your code. It works good. But if you want optimize it try to use this:
Dim mypics(),num
Sub Object_OnScriptEnter
ReDim Preserve mypics(0)
mypics(0) = ""
num = 0
End Sub
Sub Object_OnDropFiles(files)
Call MakeStream(files,0)
End Sub
Sub MakeStream(strx,n)
On Error Resume Next
ReDim mypics(0)'<== clear the array
mypics(0) = ""
num = 0
myitems = split(strx,"|")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each item In myitems
If objFSO.FolderExists(item) Then
Set objFolder = objFSO.GetFolder(item)
Call AddFiles_Ex(objFSO,item,n) '<== if item is folder send it to the other Sub
Set objFolder = nothing
ElseIf objFSO.FileExists(item) Then
ext = LCase(objFSO.GetExtensionName(item))
If IsImage(ext) Then '<== checking for file extension
Set objFile = objFSO.GetFile(item)
ReDim Preserve mypics(n) '<== if item is file add it into array
mypics(n) = objFile.path
n = n + 1
Set objFile = nothing
End If
End If
Next
Set objFSO = nothing
If len(mypics(num)) > 5 Then
Object.Picture = mypics(num) '<== apply the first picture
object.SetTimer 1, 8000
Else
msgbox "No images found"
End If
If err.number > 0 Then err.clear
End Sub
'< Example of usage the Recursive method to get files>
Sub AddFiles_Ex(objFSO,fp,n) '<== This code will allow you to get Files not only from Folders
On Error Resume Next 'bat from each SubFolders in this Folder.
Set objFOL = objFSO.GetFolder(fp)
Set objFIL = objFOL.Files
If objFIL.count > 0 Then
For Each item In objFIL
ext = LCase(objFSO.GetExtensionName(item.path))
If IsImage(ext) Then
ReDim Preserve mypics(n)
mypics(n) = item.path
n = n + 1
End If
Next
End If
Set objSUB = objFOL.SubFolders
If objSUB.count > 0 Then
For Each subitem In objSUB
Call AddFiles_Ex(objFSO,subitem.path,n)
Next
End If
Set objSUB = nothing
Set objFIL = nothing
Set objFOL = nothing
End Sub
Function IsImage(ext)
Select Case ext
Case "bmp","png","ico","jpg","tga" IsImage = True
Case Else IsImage = False
End Select
End Function
Sub Object_Ontimer1
If num > UBound(mypics) Then num = 0 Else num = num + 1
Object.Picture = mypics(num)
End Sub
Sub Object_OnStateChange(state)
If state="Command executed" Then
System.SetWallpaper Object.Directory & "vista-1.bmp", 3
End If
End Sub
Sub Object_OnScriptExit
Erase mypics
object.KillTimer 1
End Sub
Best Regards.