Windows 10 hta script to display animated GIFs in a folder and its subfolders

PeterCo

New Member
Joined
Sep 23, 2018
Messages
5
Dear Community,

in the Windows 7 Forum I found a working hta script to display animated GIFs located in a folder:
Animate GIF files in Windows Explorer?

Here is the hta script:

Code:
<html><head><title>Animator</title></head>
<body><script type="text/vbs">
set fso=CreateObject("Scripting.FileSystemObject")
set fldr=fso.GetFolder(".")
for each file in fldr.files
if lcase(right(file.name,4))=".gif" then
document.write "<img src=""" & file.name & """>"
end if
next
</script></body></html>

Is there any way to modify this script, so it can not only display and animate GIFs of the folder where the hta file is located, but also include every subfolder in this folder?

Best regards,
PeterCo
 


Code:
set fso=CreateObject("Scripting.FileSystemObject")
set fldr=fso.GetFolder(".")

WalkFolder fldr

Sub WalkFolder(CurrentFolder)
    Dim SubFolder
    For Each SubFolder In CurrentFolder.SubFolders
        WalkFolder SubFolder
    Next

    Dim CurrentFile
    For Each CurrentFile in CurrentFolder.Files
        IF lcase(right(CurrentFile.name,4))=".gif" then
            document.write "<img src=""" & CurrentFile.name & """>"
        end if
    Next
End Sub

This will recursively walk to the bottom of the directory structure and then process all the files. If you want it to only go a certain depth you could add a depth counter to the WalkFolder subroutine and stop walking at a programmed depth.
 


Last edited by a moderator:
Code:
set fso=CreateObject("Scripting.FileSystemObject")
set fldr=fso.GetFolder(".")

WalkFolder fldr

Sub WalkFolder(CurrentFolder)
    Dim SubFolder
    For Each SubFolder In CurrentFolder.SubFolders
        WalkFolder SubFolder
    Next

    Dim CurrentFile
    For Each CurrentFile in CurrentFolder.Files
        IF lcase(right(CurrentFile.name,4))=".gif" then
            document.write "<img src=""" & CurrentFile.name & """>"
        end if
    Next
End Sub

This will recursively walk to the bottom of the directory structure and then process all the files. If you want it to only go a certain depth you could add a depth counter to the WalkFolder subroutine and stop walking at a programmed depth.

Thank you very much! :)
But there is one problem left: The script seems to find every GIF in the subfolders of the current folder. But while it correctly displays the GIFs of the current folder / main folder, all GIFs of the subfolders look like this: (see the attached picture).

Best regards,
PeterCo

GIF Display Fail.webp
 


Back
Top