The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
OK,
I am wondering if anyone can help me in doing this
I have 3 folders: miscelaneous, travel & family
each folder contains x number of pics either in jpg or gif
Now from time to time users may add a new pic
what I want to do is display the las 5 recents pics from out of the three folders.
how can I do this? the way I do is display the folder as link and then once clicked display the pictures which is not elegant. Any ideas?
thank you!
I am wondering if anyone can help me in doing this
I have 3 folders: miscelaneous, travel & family
each folder contains x number of pics either in jpg or gif
Now from time to time users may add a new pic
what I want to do is display the las 5 recents pics from out of the three folders.
how can I do this? the way I do is display the folder as link and then once clicked display the pictures which is not elegant. Any ideas?
thank you!
Posted
Easy enough if you'll provide a link to that page in .txt format for us to look at.
Posted
OK,
I got the code but is throwing a message indicating that a folder does not exists,
I cleaned the code a bit ( believe me was messy like hell)
any help is welcome
I got the code but is throwing a message indicating that a folder does not exists,
I cleaned the code a bit ( believe me was messy like hell)
any help is welcome
Code:
<%
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorLocation = 3 ' adUseClient
objRS.Fields.Append "Name", 200, 50 ' adVarChar
objRS.Fields.Append "created", 7 ' adDate
objRS.Open
'This script creates an image gallery using the FileSystemObject
'See the attached help file for more details
'The directory where you folders are at
'This is all you need to change for this script to work
'*******************************************************
'imagespath = "C:\inetpub\wwwroot\image\"
imagespath =server.mappath(".\album\")
'*******************************************************
Dim FSObj, FOlderObj, FileCollObj
Set FSObj = Server.CreateObject("Scripting.FileSystemObject")
if request.querystring("gallery") = "" then
Set FolderObj = FSObj.GetFolder(imagespath)
Set FolderCollObj = FolderObj.SubFolders
For Each item in FolderCollObj
Set SubFolderObj = FSObj.GetFolder(FolderObj & "/" & item.name)
objRS.AddNew
objRS("Name") = item.name
objRS("created") = SubFolderObj.DateCreated
'response.write "<a href=""gallery_info.asp?gallery=" & item.name & """>" & item.name & "</a><br><br>"
Next
objRS.Sort = "created DESC"
objRS.MoveFirst
Dim carpetas
Do UNTIL objRS.EOF
carpetas=""
'*** do not display the link for ths subfolders
'response.write "<a href=""gallery_info.asp?gallery=" & objRS(0) & """>"
'response.write objRS(0) & " <BR><BR></A>"
carpetas =objRS(0)
response.write "<table align=""center"" width=""50%""> <tr>"
Set FolderObj = FSObj.GetFolder(imagespath &"\" & carpetas & "")
Set FileCollObj = FolderObj.Files
For each item in FileCollObj
If x = 2 Then
response.write "<TR>"
End If
imagespath ="album/"
response.write "<td><a href=""" & imagespath & carpetas & "/" & item.name & """><img src=""" & imagespath & carpetas & "/" & item.name & """ height=""100"" width=""100""></a></td>"
x = x + 1
response.write "</TR></TABLE>"
Next
objRS.movenext
Loop
'**********************************end of going into the subfolders
end if
%>
Last edited by AnonJr on 18 November 2010, 08:08
Posted
I threw that all out lol.
Prerequisites: you can have only images in the subfolders (the program doesn't include a file-type regex), and I left it only one level deep. If you need it to be recursive (folders within subfolders, etc.), it'll need a bit more code.
Here you go:
Prerequisites: you can have only images in the subfolders (the program doesn't include a file-type regex), and I left it only one level deep. If you need it to be recursive (folders within subfolders, etc.), it'll need a bit more code.
Here you go:
Code:
<%
Dim rsFSO, objFSO, objFolder, File, strFolder
strFolder = "album"
strFold = "album"
FolderList
Sub Output
Response.Write "<table align=""center"" width=""50%""><tr valign=""middle"">"
i = 0
Do while Not rsFSO.EOF
Response.Write " <td align=""center"" width=""20%""><a href=""" & strFold & "/" & rsFSO("Name") & """><img src=""" & strFold & "/" & rsFSO("Name") & """ height=""100"" width=""100""></a></td>"
i=i+1
if i=5 then exit do
rsFso.MoveNext
Loop
End Sub
Function FolderList
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.Mappath(strFolder))
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
strFold = strFolder & "\" & objSubfolder.Name
FileSorter
Call Output
Next
End Function
Function FileSorter
Const adInteger = 3
Const adDate = 7
Const adVarChar = 200
Set rsFSO = Server.CreateObject("ADODB.Recordset")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.Mappath(strFold))
Set objFSO = Nothing
With rsFSO.Fields
.Append "Name", adVarChar, 200
.Append "Type", adVarChar, 200
.Append "DateCreated", adDate
.Append "DateLastAccessed", adDate
.Append "DateLastModified", adDate
.Append "Size", adInteger
.Append "TotalFileCount", adInteger
End With
rsFSO.Open
For Each File In objFolder.Files
If (Left(File.Name, 1)) <> "_" Then
rsFSO.AddNew
rsFSO("Name") = File.Name
rsFSO("Type") = File.Type
rsFSO("DateCreated") = File.DateCreated
rsFSO("DateLastAccessed") = File.DateLastAccessed
rsFSO("DateLastModified") = File.DateLastModified
rsFSO("Size") = File.Size
rsFSO.Update
End If
Next
rsFSO.Sort = "DateCreated DESC "
Set objFolder = Nothing
rsFSO.MoveFirst
Set fsoFiles = rsFSO
End Function
rsFSO.close
Set rsFSO = Nothing
objFSO.Close
set objFSO = Nothing
%>
Last edited by Carefree on 18 November 2010, 08:29
Posted
YOU ARE DA MAN!!!!!!!!
I got an error
Microsoft VBScript runtime error '800a01a8'
Object required, line 85
Then I comment out
from: rsFSO.close
Set rsFSO = Nothing
objFSO.Close
set objFSO = Nothing
to: rsFSO.close
Set rsFSO = Nothing
'objFSO.Close
set objFSO = Nothing
And looks like a charm :)
thank you! BTW yes the prerequisite is well taken :)
Microsoft VBScript runtime error '800a01a8'
Object required, line 85
Then I comment out
from: rsFSO.close
Set rsFSO = Nothing
objFSO.Close
set objFSO = Nothing
to: rsFSO.close
Set rsFSO = Nothing
'objFSO.Close
set objFSO = Nothing
And looks like a charm :)
thank you! BTW yes the prerequisite is well taken :)
Posted
Good enough. Glad I could help.
Email Member
Message Member
Post Moderation
FileUpload
If you're having problems uploading, try choosing a smaller image.
Preview post
Send Topic
Loading...