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

An image from 'hta script to display animated GIFs in a folder and its subfolders'. The image shows an application window with broken or missing icons represented by placeholder symbols.
 

Last edited by a moderator:
Did you make sure to replace your entire script?
 

Did you make sure to replace your entire script?

Sure. Any idea what could cause the issue?

Best regards,
PeterCo
 

I'd say look at the img src= and see if they are valid paths
 

Solution
I'd say look at the img src= and see if they are valid paths
Seems fine...
I just can't get the script to display the subfolder GIFs correctly. :confused:
 

I'd say look at the img src= and see if they are valid paths

Is "text/vbs" the right script type?
 

Yes
 

Back
Top
\n\nIs 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?\n\nBest regards,\nPeterCo","answerCount":8,"upvoteCount":0,"author":{"@type":"Person","@id":"https://windowsforum.com/members/peterco.103837/","name":"PeterCo","url":"https://windowsforum.com/members/peterco.103837/"},"acceptedAnswer":{"@type":"Answer","datePublished":"2018-09-24T03:31:56+00:00","url":"https://windowsforum.com/posts/718548/","text":"I'd say look at the img src= and see if they are valid paths","upvoteCount":1,"author":{"@type":"Person","@id":"https://windowsforum.com/members/neemobeer.91900/","name":"Neemobeer","url":"https://windowsforum.com/members/neemobeer.91900/"}},"suggestedAnswer":[{"@type":"Answer","datePublished":"2018-09-26T21:33:52+00:00","url":"https://windowsforum.com/posts/718729/","text":"Yes","upvoteCount":0,"author":{"@type":"Person","@id":"https://windowsforum.com/members/neemobeer.91900/","name":"Neemobeer","url":"https://windowsforum.com/members/neemobeer.91900/"}},{"@type":"Answer","datePublished":"2018-09-26T20:28:48+00:00","url":"https://windowsforum.com/posts/718724/","text":"I'd say look at the img src= and see if they are valid paths\n\nIs \"text/vbs\" the right script type?","upvoteCount":0,"author":{"@type":"Person","@id":"https://windowsforum.com/members/peterco.103837/","name":"PeterCo","url":"https://windowsforum.com/members/peterco.103837/"}},{"@type":"Answer","datePublished":"2018-09-24T17:57:42+00:00","url":"https://windowsforum.com/posts/718584/","text":"I'd say look at the img src= and see if they are valid paths\nSeems fine...\nI just can't get the script to display the subfolder GIFs correctly. :confused:","upvoteCount":0,"author":{"@type":"Person","@id":"https://windowsforum.com/members/peterco.103837/","name":"PeterCo","url":"https://windowsforum.com/members/peterco.103837/"}}]},"publisher":{"@type":"Organization","name":"Windows Forum","alternateName":"WindowsForum","description":"Join a vibrant community of Windows users and get expert help and support for your Windows 11 and 10 issues. Our forums cover a range of topics, from software updates to troubleshooting tips and performance optimization. Get the answers you need and join the conversation today at Windows Forum.","url":"https://windowsforum.com","logo":"https://windowsforum.com/styles/default/xenforo/logo.og.webp"}}