ASP: Scripting.FileSystemObject... show folder content
This is the last post of the Scripting.FileSystemObject series. After seeing how to manipulate files and folders, how to upload files and how to get file information, I would like to show how to retrieve a folder's content. This is probably the most easy thing to do, and as usual we start by setting the variables and the object:
and use the size method. Change the ... line with:
If you want to make the file name clickable, replace the above line with:
As you can see you can play around with all the information and manipulate them according to your needs.
Related posts:
ASP: Scripting.FileSystemObject... how to read file or folder information
JQuery: 5 useful file upload plugins
ASP: Scripting.FileSystemObject... how to move, copy and delete a file or a folder
<%
Dim FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Dim folderpath
folderpath = Server.MapPath(yourfolder)
Change yourfolder with something like "/doc/". Then we get the content:Set fileinfo = FSO.GetFolder(folderpath)
%>
We can show the content with:
<%For each filefound in fileinfo.Files
%>
<%=filefound.Name%>
<%Next%>
All the files in the folder are now displayed in a table. You can add different information on the file, for example the size: just add a new <%=filefound.Name%> <%=filefound.Size%>
And so on...If you want to make the file name clickable, replace the above line with:
"><%=filefound.Name%> <%=filefound.Size%>
As a side note on file size, you could add a little if... then.. else clause to make the size more readable: if Clng(filefound.Size) < 1024 then
VarSize = filefound.Size & " bytes"
else
VarSize = Clng(filefound.Size / 1024) & " KB"
end if
Afterwards replace <%=filefound.Size%> in your table with <%=VarSize%>.As you can see you can play around with all the information and manipulate them according to your needs.
Related posts:
ASP: Scripting.FileSystemObject... how to read file or folder information
JQuery: 5 useful file upload plugins
ASP: Scripting.FileSystemObject... how to move, copy and delete a file or a folder