2

First all of this activity is considered local. Simply put there is no web server.

I have a two step process.

  1. Use VBS to create an html file and populate it with links to images in a specific folder I type into a msgbox.

  2. Open the html file in browser of my choice.

I've spent a fruitless evening trying to combine this into a single step - html page has an input box, press button --> images appear.

Just to be clear at the moment the VBS script output simply has

img src="c:\temp\01.png"

with opening and closing tags, where there is a file called 01.png in the folder temp, and then 02.png would be below that etc.

My attempt this evening was to find a way to simply display a list of files onto the page with something like document.write, or its equivalent, but I didn't get that far. Any attempt to access the file system seems to cause the script to fail.

Thanks for any help.

I have a vbscript at the moment for my first step. I would like to know how to embed the function / html output into a single html file.

I envisage that the html page would have an input field, a 'go' button, and then the results would be the images in the folder appearing on the page. All using client sided scripting.

My vbscript is pretty similar to the one below, but since I know I'm only going to be given png's that's all I look for (and all that should be there for that matter).

Sorry if I keep putting things in the wrong place.

Current HTML sample output is below.

<html><head></head><body>
<img src = "c:\temp\credit.png"<hr>.<hr>
<img src = "c:\temp\NTK_01.png"<hr>.<hr>
</body></html>

-

dim objFSO
dim objFolder
dim colFiles
dim filelist
dim objStartFolder
dim pathToImage
dim iend

iend = """<hr>.<hr>" & vbcrlf   'vbcrlf if for readability of html only
const isrc = "<img src = """

const FileToWrite = "c:\temp\images.html"
'const objStartFolder = "C:\Temp"  'Used when testing so don't have to have the input box.
const For_Appending = 8
const For_Writing = 2

objStartFolder = InputBox("Folder path to open i.e. c:\temp")  'Grab the user path.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)   'No error checking cause its just me
Set colFiles = objFolder.Files


filelist = "<html><head></head><body>" & vbcrlf   'Create the html code and store it in this variable.


For Each objFile in colFiles
'There should only be images, but i created this when testing and left it in.
    if right(objFile.Name,3) = "png" then
        pathToImage = objFolder.path & "\" & objFile.Name       
        filelist = filelist & isrc & pathToImage  & iend
'Output line should be:
'<img src="c:\temp\01.png"><hr>.<hr>
    end if
Next

filelist = filelist & "</body></html>"      'Close the html data
wscript.echo filelist               'Show what the html file will look like - sanity check.

'Open the file, overwrite the existing contents and close the file
set htmlout = objFSO.OpenTextFile(FileToWrite,For_Writing,TRUE)
htmlout.write filelist
htmlout.close
  • 1
    Do you have some code in from your HTML file you could share? Are you wrapping your your src like ``? – David Aug 03 '15 at 00:43
  • i don't know vbs but it seems you may find the answer here. http://www.tutorialspoint.com/vbscript/vbscript_fso_objects.htm and perhaps http://www.html5rocks.com/en/tutorials/file/filesystem/ . – Ken Kwok Aug 03 '15 at 00:52
  • You should be using the file uri scheme too to link to local files http://stackoverflow.com/questions/2148584/open-a-direct-file-on-the-hard-drive-from-firefox-file – Matthew Lock Aug 03 '15 at 01:31
  • Because everything is local and no web server I hoped I could side step around the security issue. The filesystem that Ken Kwok linked doesn't appear to be supported going forward. Of course I could be mistaken about that. – OneQuestionOnly Aug 03 '15 at 21:02

1 Answers1

2

You can start with this example : IMG2HTML.vbs

'This VBScript Scan and Search for images with extension like jpg,gif,png,bmp 
'in the folder and subfolders and list them in a html output file.
'© Hackoo © 2011
start_folder = ".\" ' The Current Directory for scaning images
htmfile = "ListImage.htm"
ext = Array("jpg","gif","png","bmp") 
count=0
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(start_folder)
Set ws = CreateObject("WScript.Shell")
Set outfile = fso.CreateTextFile(htmfile)
outfile.WriteLine "<html><body>"
ListDirectory folder, ext    'Call The Recursive function
outfile.WriteLine "<br><center><font color=red>Le Nombre total des images est de "& count & "</font>"
outfile.WriteLine "</body></html>"
outfile.Close
Question = MsgBox("The Total Count of images is " & count & vbCrLf &" Do you want to List them now ?",vbYesNo+32,"Total Count of images")
If Question = vbYes Then
    Explorer htmfile
else
    wscript.Quit
End If
'******************************************
Sub ListDirectory(folder, ext)
    For Each file In folder.Files
        cheminFic = folder & "\" & file.name
        For i = lbound(ext) to ubound(ext)
            If UCase(ext(i)) = UCase(fso.GetExtensionName(file.Name)) Then
                strFilePath = file.ParentFolder
                outfile.WriteLine "<center><a target=_Blank href="& qq("file:///" & cheminFic) &""">"&_
                "<img src="& qq("file:///" & cheminFic) &" width=70 height=70><BR><B><font color=red>"&_
                "<a href="& qq("file:///" & strFilePath) &">" & file.Name & "</a></font><B><br><hr>"
                count=count+1
            End If
        Next        
    Next
    For Each fldr In folder.subfolders
        ListDirectory fldr, ext
    Next
End Sub
'******************************************
Function Explorer(File)
    Set ws=CreateObject("wscript.shell")
    ws.run "Explorer "& File & "\"
end Function
'******************************************
Function qq(strIn) 
    qq = Chr(34) & strIn & Chr(34)
End Function
'******************************************
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • I have a vbscript at the moment for my first step. I would like to know how to embed the function / html output into a single html file. I envisage that the html page would have an input field, a 'go' button, and then the results would be the list of images. My vbscript is pretty similar to yours, but since I know I'm only going to be given png's that's all I look for (and all that should be there for that matter). – OneQuestionOnly Aug 03 '15 at 20:29
  • Did you mean by HTML a HTA ?? – Hackoo Aug 04 '15 at 07:30