【问题标题】:Use a single html file to show all the images in a local folder使用单个 html 文件显示本地文件夹中的所有图像
【发布时间】:2015-10-25 00:15:42
【问题描述】:

首先,所有这些活动都被视为本地活动。简而言之,没有网络服务器。

我有一个两步流程。

  1. 使用 VBS 创建一个 html 文件,并用我在 msgbox 中键入的特定文件夹中的图像链接填充它。

  2. 在我选择的浏览器中打开 html 文件。

我花了一个徒劳的晚上试图将其组合成一个步骤 - html页面有一个输入框,按下按钮-->图像出现。

现在要清楚的是,VBS 脚本输出只是有

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

带有开始和结束标签,其中temp文件夹中有一个名为01.png的文件,然后02.png会在下面等等。

我今晚的尝试是找到一种方法,使用类似 document.write 或类似的东西在页面上简单地显示文件列表,但我没有做到这一点。任何访问文件系统的尝试似乎都会导致脚本失败。

感谢您的帮助。

我目前有一个 vbscript 用于我的第一步。我想知道如何将函数/html 输出嵌入到单个 html 文件中。

我设想 html 页面将有一个输入字段、一个“开始”按钮,然后结果将是页面上出现的文件夹中的图像。全部使用客户端脚本。

我的 vbscript 与下面的非常相似,但因为我知道我只会得到 png 的文件,这就是我要寻找的所有内容(并且所有这些都应该在那里)。

对不起,如果我一直把东西放在错误的地方。

当前的 HTML 示例输出如下。

<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

【问题讨论】:

标签: javascript html vbscript


【解决方案1】:

你可以从这个例子开始: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
'******************************************

【讨论】:

  • 我现在有一个 vbscript 用于我的第一步。我想知道如何将函数/html 输出嵌入到单个 html 文件中。我设想 html 页面将有一个输入字段、一个“开始”按钮,然后结果将是图像列表。我的 vbscript 和你的很相似,但是因为我知道我只会得到 png's 这就是我要寻找的所有东西(以及所有应该存在的东西)。
  • 你的意思是 HTML 和 HTA 吗??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
  • 2012-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-27
  • 1970-01-01
相关资源
最近更新 更多