使用SQL返回图片文件夹中最后添加的图片

时间:2015-06-22 14:13:40

标签: sql vbscript asp-classic

我有一个链接到访问数据库的Web应用程序。 Web应用程序拍摄照片并将其存储在文件夹中。我试图通过尝试检索添加到图片文件夹的最后一张图片来将记录链接到文件。

每张图片都以日期和时间作为文件名,例如20150615105326.jpg。 所以我基本上需要检索MAX(filename),但不知道如何。

我正在研究SQL查询:

`Dim newestpic, SQL1
newestpic = ew_execute(select newest picture in folder - this is where I need help)
SQL1 = ("UPDATE [Visitors] SET [Image] = "http://localhost/photos/" & newestpic & " WHERE thisID = thatID");")
Call ew_Execute(SQL1)`

我只需要帮助设置最新的。我已经研究了几个小时但无处可去,请帮忙。

再次@Bond。 ' Row Updated event Sub Row_Updated(rsold, rsnew) server.CreateObject("WScript.Shell") Dim newestpic, SQL1
newestpic = .Exec("%comspec% /c dir ""C:\Users\ashwortm\Desktop\testcam1\Photos"" /a-d /b /o-d *.jpg").StdOut.ReadLine SQL1 = ("UPDATE [Visitors] SET [visname] = "http://localhost/photos/" & newestpic & "" WHERE [Table1].[ID] = 1;")
Call ew_Execute(SQL1)
End Sub

好的@Bond的帮助和研究到目前为止我有...... ' Row Updated event Sub Row_Updated(rsold, rsnew) Dim oShell, SQL1 set oshell=server.createobject("WScript.Shell")
oshell.run "cmd.exe /c dir ""C:\Users\ashwortm\Desktop\testcam1\Photos"" /a-d /b /o-d *.jpg".StdOut.ReadLine SQL1 = ("UPDATE [Visitors] SET [visname] = "http://localhost/photos/" & oShell & "" WHERE [Table1].[ID] = 1;") set oShell=nothing
Call ew_Execute(SQL1

这仍然无效,但我觉得我越来越近了。任何人都可以发现上述代码中的任何错误吗?

1 个答案:

答案 0 :(得分:1)

您可以使用FileSystemObject迭代所有文件,这可能是大多数VBScripters会做的。

但是,如果您不介意命令提示符的闪存,请使用可靠的dir命令为您工作。

Set oShell = Server.CreateObject("WScript.Shell")

' Sorted by filename (what you requested)...
newestpic = oShell.Exec("%comspec% /c dir ""c:\my folder\*.jpg"" /a-d /b /on").StdOut.ReadLine

' Or, sorted by date (may work even better for you)...
newestpic = oShell.Exec("%comspec% /c dir ""c:\my folder\*.jpg"" /a-d /b /o-d").StdOut.ReadLine